Expand description

A simple LRU cache for Rust that only caches items it has seen at least once before. The size of its internal memory is adjustable.

Why?

I didn’t want to use a fixed cache size when I expect that most data will not be fetched twice, and that most of the time the number of items benefitting from caching will be small. Good use cases: parsing large data structures that frequently cross-reference the same data chunk, reading a set of dictionary-compressed files where there are several different dictionaries, reading many files that all refer to shared parser profiles (eg. color profiles in images), etc.

Sure, a fixed size cache that stores “seen once” items would also work, but the memory usage would be higher than really necessary. Hence, this crate.

Structs

  • A cache that will only hold onto items that have been reqeuested more than once in recent memory. Single-use items are not held at all. Once an item is requested twice, it is cached until all memory of seeing it requested has expired. The length of the memory is adjustable, and must be set at initialization.
  • A cache that will only hold onto items that have been requested more than once in recent memory. Single-use items are not held at all. Once an item is requested twice, it is cached until all memory of seeing a request has expired. The length of the memory is adjustable, and must be set at initialization.