#object-pool #buffer #cache #pool

poolcache

A hybrid object pool and LFU cache that permits cached object reuse. Useful for avoiding allocations

2 releases

Uses old Rust 2015

0.1.1 Apr 9, 2016
0.1.0 Apr 9, 2016

#341 in Caching

Download history 22/week @ 2024-07-22 75/week @ 2024-07-29 27/week @ 2024-08-05 8/week @ 2024-08-12 6/week @ 2024-08-19 50/week @ 2024-08-26 14/week @ 2024-09-02 79/week @ 2024-09-09 128/week @ 2024-09-16 202/week @ 2024-09-23 27/week @ 2024-09-30 15/week @ 2024-10-07 32/week @ 2024-10-14 61/week @ 2024-10-21 41/week @ 2024-10-28 14/week @ 2024-11-04

148 downloads per month
Used in nut

MIT license

8KB
100 lines

poolcache

A hybrid LFU cache and object pool that allows values to be cached and easily reused.


lib.rs:

A PoolCache is a hybrid LFU cache and object pool, that allows for caching behavior with the possibility of reusing object rather than dropping them from the cache automatically.

Examples

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();

No runtime deps