file-lfu
A least-frequently-used cache layered on a directory.
Quick start
- Implement
AsyncFileReprfor the type you intend to cache.- Optionally if you want to use your own type as cache key, implement
Keyfor your cache key type.
- Optionally if you want to use your own type as cache key, implement
- Initialise the cache using
FileBackedLfuCache::init. - Add new items to the cache using
FileBackedLfuCache::push.- Items will not be flushed to disk until cache capacity is exceeded.
- Use
FileBackedLfuCache::{flush, flush_all}to trigger a flush manually.
- Use
FileBackedLfuCache::{get, get_or_load}to access items immutably. - Use
FileBackedLfuCache::{get_mut, get_or_load_mut}to access items mutably.
Example
use FileBackedLfuCache;
use Uuid;
Features
uuid-as-key
Implement the Key trait for uuid::Uuid,
so that you can use it as the key directly.
Using this feature adds uuid as a dependency.
This feature is enabled by default.
Why not just rely on OS and/or filesystem level caching?
You should, when possible. It's free and requires no work on the part of the developer.
However, there are cases where you may wish for more granular control over what things get cached and if they are cached. This is when this crate comes in handy.
Notably, this crate allows you to perform arbitrary serialisation and deserialisation while loading and flushing, enabling you to cache an easier-to-work-with representation of the underlying data in memory.