Skip to content

Commit 2b53da9

Browse files
fix(cache): fix recursive cache purges (#3221)
* feat(engine): add RocksDB engine run script * fix(udb): fix rocksdb conflict tracker * chore: bump version to 25.8.0 --------- Co-authored-by: MasterPtato <[email protected]>
1 parent 1fd5f93 commit 2b53da9

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

packages/common/cache/build/src/req_config.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,31 @@ impl RequestConfig {
320320
}
321321
}
322322

323+
// Delete keys locally
324+
let raw_keys = cache_keys
325+
.into_iter()
326+
.map(RawCacheKey::from)
327+
.collect::<Vec<_>>();
328+
self.purge_local(base_key, raw_keys).await
329+
}
330+
331+
/// Purges keys from the local cache without publishing to NATS.
332+
/// This is used by the cache-purge service to avoid recursive publishing.
333+
#[tracing::instrument(err, skip(keys))]
334+
pub async fn purge_local(
335+
self,
336+
base_key: impl AsRef<str> + Debug,
337+
keys: Vec<RawCacheKey>,
338+
) -> Result<()> {
339+
let base_key = base_key.as_ref();
340+
341+
if keys.is_empty() {
342+
return Ok(());
343+
}
344+
345+
// Convert RawCacheKey to String for driver
346+
let cache_keys = keys.into_iter().map(|k| k.cache_key()).collect::<Vec<_>>();
347+
323348
// Delete keys locally
324349
match self.cache.driver.delete_keys(base_key, cache_keys).await {
325350
Ok(_) => {

packages/services/cache-purge/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ pub async fn start(config: rivet_config::Config, pools: rivet_pools::Pools) -> R
2626
"received cache purge request"
2727
);
2828

29-
// Purge the cache locally
29+
// Purge the cache locally without publishing to NATS again
3030
if let Err(err) = cache
3131
.clone()
3232
.request()
33-
.purge(&purge_msg.base_key, purge_msg.keys)
33+
.purge_local(&purge_msg.base_key, purge_msg.keys)
3434
.await
3535
{
3636
tracing::error!(?err, base_key = ?purge_msg.base_key, "failed to purge cache");

0 commit comments

Comments
 (0)