AGPL ๐
Edit: this looks pretty slick, Iโll keep it in mind next time I need a cache
AGPL ๐
Edit: this looks pretty slick, Iโll keep it in mind next time I need a cache
Thanks, would appreciate any feedback if you end up using it!
When the market doesn't have exactly what you need, the most powerful thing you can do is build your own version.
ELI5? ๐
So if you consider a database that has billions of rows of data and typically resides on a relatively slow SSD/HDD, trying to retrieve any data can take a while. An in-memory cache is a small mini-database that saves just the most important data from the database and holds it in memory (DRAM) to make accessing that data a lot faster.
The cache has to be small because DRAM is much more expensive than an SSD/HDD. It can therefore only hold a small subset of the data from the database and has a set limit on the amount of data it can hold. So what happens if you want to add new data to the cache but it's already full? Well you have to select some data in the cache to evict to make room for the new data. The way you select that data is called the eviction policy.
The most common eviction policy is least recently used (LRU) which just evicts the least recently used piece of data from the cache. A simple way to implement this is to keep all the data in the cache in LRU order so it's easy to select the data to evict. But there are other eviction policies that may sometimes outperform LRU but you can't switch to them because the data is already in LRU order.
So that's what PaperCache solves. It monitors which is the best eviction policy and is able to switch between them and reorder the data as necessary.
Hope that helps!
Great explanation โค Sounds useful!
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Credits