ttlcache
ttlcache copied to clipboard
Proposal: Present cache items in order of oldest to newest
Hello everyone.
Thank you for the great cache package.
Feature request
In some cases, we want to delete the oldest cache first, when an external limit is reached, which is different from the capacity of the ttlcache.
Usecase
Specifically, we are creating a disk cache package to be used as a proxy cache.
https://github.com/2manymws/rcutil
It monitors the file size of the entire cache file while storing the cache file key in ttlcache.
When the file size limit is reached, we want to delete the cache in order of oldest to newest from the information held by ttlcache.
In https://github.com/2manymws/rcutil/pull/48, we modified it to have its own LRU, but we realized that if we could refer to the Cache.items.lru of ttlcache, we would not need to make such a complicated modification.
Proposal
We thought of two implementations.
If you choose, we can present the implementation via Pull Request.
- Provide a function that returns Items in reverse order to Cache.Range
-
Cache.RangeInReverse
orCache.Reverse
?
-
- Extend Cache.Range to allow passing the option to reverse the order.
-
func (c *Cache[K, V]) Range(fn func(item *Item[K, V], opts ...RangeOption) bool)
-
Thank you!