#cache #object-pool #pool #buffer

poolcache

一种混合对象池和LFU缓存,允许缓存对象的复用。有助于避免分配

2个版本

使用旧的Rust 2015

0.1.1 2016年4月9日
0.1.0 2016年4月9日

#292缓存

Download history 2/week @ 2024-01-03 44/week @ 2024-01-10 120/week @ 2024-01-24 137/week @ 2024-01-31 404/week @ 2024-02-07 305/week @ 2024-02-14 126/week @ 2024-02-21 105/week @ 2024-02-28 119/week @ 2024-03-06 375/week @ 2024-03-13 163/week @ 2024-03-20

810 每月下载量
nut 中使用

MIT 许可证

8KB
100

poolcache

PoolCache 是一种混合LFU缓存和对象池,允许缓存值并轻松复用。


lib.rs:

PoolCache 是一种混合LFU缓存和对象池,允许缓存行为,同时也有可能复用对象而不是自动将它们从缓存中删除。

示例

use poolcache::PoolCache;

// Create a new pool cache with a maximum 'heat' of 4.
// Larger maxium heat values make popular values more resistent
// to being reused, but at the cost of increasing the potential
// work required to find a re-usable entry.
let mut cache : PoolCache<u64, Vec<u8>> = PoolCache::new(4);

// Caches are empty until you populate them..`insert` adds a 
// new value associated with a key.
cache.insert(1, Vec::new());

// `cache` now contains a single vector, associated with the key
// `1`, which can be retrieved with `get`
{
    let vecref : &Vec<u8> = cache.get(&1).unwrap();
}

// You can also add values that aren't associated with any key with
// `put`. These newly added values will be used to satisfy `take`
// requests before evicting objects with keys.
cache.put(Vec::new());

// You can get an owned object from the pool using `take`. This will
// use any free objects (if available), or evict the least `hot`
// key from the cache, and return its value.
let ownedvec : Vec<u8> = cache.take().unwrap();

无运行时依赖