tiny-cache
Avoid doing the same work again when you already have the result. Save results for later, with a limit on how much you keep.
FifoCachekeeps a chosen number of results, removing the oldest added result when full. You can change the limit as your needs change.LRUCachelets several users share results they recently used. Once nobody needs a saved result, the cache lets it go.
Example
For example, if you count the words in the same text several times, save the count rather than read through the text every time.
use FifoCache;
let mut saved = new;
assert_eq!;
assert_eq!;
saved.set_capacity;
Share results between users
Choose LRUCache when different parts of your program need the same result. In Freya, several labels can reuse the work of preparing the same text for drawing. Removing one label should not discard work another label still needs.
Each user keeps its last two results by default. Call utilize to look for a saved result, insert if you need to create it, and remove when a user no longer needs its results.
Run the example showing both caches: