Skip to content

Commit 2b99f57

Browse files
YousefSalamafacebook-github-bot
authored andcommitted
add insert_or_replace_handle method to VolatileLruCachePool
Summary: Add `insert_or_replace_handle` method to `VolatileLruCachePool`. `insert_or_replace_handle` is different from `insert_handle` in that it replaces the handle's data if its key is already present in the cache. Reviewed By: RajivTS Differential Revision: D79246894 fbshipit-source-id: c1c70c4313395b9b30fd91738e37522fa7d63996
1 parent 6b0abad commit 2b99f57

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

cachelib/rust/src/lrucache.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,14 @@ impl VolatileLruCachePool {
11231123
})
11241124
}
11251125

1126+
/// Insert a previously allocated handle into the cache, replacing any pre-existing data.
1127+
pub fn insert_or_replace_handle(&self, handle: LruCacheHandle<ReadWrite>) -> Result<()> {
1128+
self.inner.insert_or_replace_handle(LruCacheHandle {
1129+
handle: handle.handle,
1130+
_marker: PhantomData,
1131+
})
1132+
}
1133+
11261134
/// Insert a key->value mapping into the pool. Returns true if the insertion was successful,
11271135
/// false otherwise. This will not overwrite existing data.
11281136
pub fn set_with_ttl<K, V>(&self, key: K, value: V, ttl: Option<Duration>) -> Result<bool>

0 commit comments

Comments
 (0)