I have a software project that creates a series of fingerprint values ββ(hash) from objects of different sizes. The larger the object, the more expensive the hash is. Hashes are used for comparative purposes.
Now I want to cache hash values ββto improve the performance of subsequent comparisons. For any given cache entry, I have the following metrics:
- number of hits
- date and time of the last modification
- hashed object size
So to my question. Given the need to limit the size of the cache (limit it to a specific number of entries), what is a balanced approach to replacing cache elements?
Obviously, larger objects are more expensive than a hash, so they need to be maintained as long as possible. However, I want to avoid a situation where filling the cache with a large number of large objects will prevent future (smaller) elements from being cached.
So, based on the metrics available to me (see above), I am looking for a good general-purpose "formula" for expiring (deleting) cache entries when filling the cache.
All thoughts, comments are appreciated.
source share