| Crates.io | memory_stash |
| lib.rs | memory_stash |
| version | 0.1.1 |
| created_at | 2025-11-02 23:30:08.529442+00 |
| updated_at | 2025-11-02 23:39:37.905237+00 |
| description | In-memory cache with policies |
| homepage | |
| repository | https://codeberg.org/nahratzah/hoard |
| max_upload_size | |
| id | 1913720 |
| size | 284,904 |
Each cache has:
Key type, that indicates the lookup key of the cache.T type, that indicates the value in the cache.Error type, that indicates the errors that can occur when using the map.Resolver, which (on a cache miss) takes a Key, and computes a Result<T, Error>.This crate contains three caches: BlockingCache, AsyncCache, and DualModeCache.
And it contains both a single-threaded version and a thread-safe version of these caches.
BlockingCache: this is a cache that waits for the resolution to finish.AsyncCache: this is a cache that uses async code, so it'll allow the program to do something else while resolution is done.DualModeCache: this cache allows both regular access (like BlockingCache) and asynchronous access (like AsyncCache).There are multiple policies that control when elements expire:
MaxAge: expire elements after a certain amount of time passes.MaxAgeErr: enable negative cache (caching of errors) and expire errors after a certain amount of time passes.MaxAgeWith: expire elements after a certain amount of time, but use a function to figure out the time.MaxAgeErrWith: enable negative cache (caching of errors) and expire errors after a certain amount of time, but use a function to figure out the time.There are multiple policies that control the size of the cache:
MaxSize: limit the cache to a specific number of elements.SimpleCostWith: limit the cache using a cost function.The cache allows you to have multiple policies in effect simultaneously using a tuple:
/// Create a cache that holds at most 1000 elements,
/// caches values for 1 hour,
/// and caches errors for 5 minutes.
(MaxSize(1000), MaxAge(Duration::from_secs(3600)), MaxAgeErr(Duration::from_secs(300)))
You can write your own policies too.
See also documentation on docs.rs and memory_stash on crates.io.