mirror of
https://github.com/rustfs/rustfs.git
synced 2026-07-27 16:48:58 +00:00
fix(cache): drain entries before clear returns (#4751)
This commit is contained in:
@@ -331,6 +331,7 @@ impl MokaBackend {
|
||||
pub async fn clear(&self) -> ObjectDataCacheInvalidationResult {
|
||||
let removed = self.index.remove_matching(|_| true).await.len();
|
||||
self.cache.invalidate_all();
|
||||
self.cache.run_pending_tasks().await;
|
||||
Self::invalidation_result(removed)
|
||||
}
|
||||
|
||||
@@ -536,6 +537,7 @@ mod tests {
|
||||
assert_eq!(result, ObjectDataCacheInvalidationResult::Removed { keys: 2 });
|
||||
assert!(matches!(backend.lookup_body(&plan_a).await, ObjectDataCacheLookup::Miss));
|
||||
assert!(matches!(backend.lookup_body(&plan_b).await, ObjectDataCacheLookup::Miss));
|
||||
assert_eq!(backend.entry_count(), 0, "clear must drain cached entries before returning");
|
||||
assert_eq!(backend.index.identity_count().await, 0, "clear must empty the identity index");
|
||||
}
|
||||
|
||||
@@ -954,9 +956,7 @@ mod tests {
|
||||
"invalidation must still win after a concurrency storm"
|
||||
);
|
||||
|
||||
// clear() plus a moka drain empties both the cache and the identity index.
|
||||
let _ = backend.clear().await;
|
||||
backend.cache.run_pending_tasks().await;
|
||||
assert_eq!(backend.entry_count(), 0, "clear() must drop every entry");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user