Skip to content

Commit bca0b6e

Browse files
markbtfacebook-github-bot
authored andcommitted
caching_ext: allow caching of bincode-enabled types
Summary: Add `bincode::Encode` and `bincode::Decode<()>` as trait bounds on cacheable types. This will allow us to switch to a bincode-backed cache. Reviewed By: RajivTS Differential Revision: D72465913 fbshipit-source-id: 6b68bf9554c5b3bb2e6261afca37ddf1fbe4605e
1 parent 8f3d508 commit bca0b6e

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

cachelib/rust/src/abomonation_cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::lrucache::VolatileLruCachePool;
2626
/// Will attempt to fetch and decode a cached item
2727
pub fn get_cached<T>(cache_pool: &VolatileLruCachePool, cache_key: &str) -> Result<Option<T>>
2828
where
29-
T: abomonation::Abomonation + Clone + Send + 'static,
29+
T: abomonation::Abomonation + Clone,
3030
{
3131
let cache_handle = cache_pool.get_handle(cache_key)?;
3232
let cache_data: Option<Vec<u8>> = match cache_handle {
@@ -60,7 +60,7 @@ pub fn set_cached<T>(
6060
ttl: Option<Duration>,
6161
) -> Result<bool>
6262
where
63-
T: abomonation::Abomonation + Clone + Send + 'static,
63+
T: abomonation::Abomonation,
6464
{
6565
let handle = cache_pool.allocate_with_ttl(cache_key, abomonation::measure(entry), ttl)?;
6666
let mut handle = handle.ok_or_else(|| Error::msg("can not allocate cachelib handle"))?;

cachelib/rust/src/bincode_cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const CONFIG: bincode::config::Configuration<
6262
/// Will attempt to fetch and decode a cached item
6363
pub fn get_cached<T>(cache_pool: &VolatileLruCachePool, cache_key: &str) -> Result<Option<T>>
6464
where
65-
T: bincode::Decode<()> + Clone + Send + 'static,
65+
T: bincode::Decode<()>,
6666
{
6767
if let Some(cache_handle) = cache_pool.get_handle(cache_key)? {
6868
let reader = cache_handle.get_reader()?;
@@ -115,7 +115,7 @@ pub fn set_cached<T>(
115115
ttl: Option<Duration>,
116116
) -> Result<bool>
117117
where
118-
T: bincode::Encode + Clone + Send + 'static,
118+
T: bincode::Encode,
119119
{
120120
let size = encoded_size(entry, CONFIG)?;
121121
let handle = cache_pool.allocate_with_ttl(cache_key, size, ttl)?;

0 commit comments

Comments
 (0)