Module sync42::lru

source ·
Expand description

A concurrent Least Recently Used cache that holds a limited number of entries, according to the size of each entry. The implementation is a concurrent, but not lock-free, structure that marries a map with a linked list.

Values for the LeastRecentlyUsedCache must be clonable. It’s expected to put them within an Arc<V> for fast cloning for types that require more than a simple set of allocations. The clone happens under a lock, so it’s on the person caring about performance to consider the cost of the clone.

Structs§

  • A least-recently-used (LRU) cache. It’s essentially a hash table and linked list that are kept in sync with each other. It is assumed that keys will be of constant size (e.g., a setsum and offset for blocks within a file, or just the setsum for open file handles). The size of the key will be used, which doesn’t cover allocations within.

Traits§

  • A Value for the LeastRecentlyUsed cache. The value has an approximate_size method that is used to compute the total size of the cache.