Skip to content

Instantly share code, notes, and snippets.

@sillypog
sillypog / retain_best_cache.cpp
Last active January 10, 2025 03:30
A cache where lowest ranked items are evicted first.
/**
* Speed up retrieval of rankable objects with a cache.
*
* We have a primary data store which implements the DataSource interface.
* Any class implementing this interface is likely to be slow as it has to
* fetch the data from disk or across the network. Therefore, it will be
* useful to temporarily store some of that data in a faster, in memory
* cache. This cache is not big enough to store all of the data from the
* primary store though.
*