Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Present cache items in order of oldest to newest #125

Open
k1LoW opened this issue Mar 1, 2024 · 0 comments
Open

Proposal: Present cache items in order of oldest to newest #125

k1LoW opened this issue Mar 1, 2024 · 0 comments

Comments

@k1LoW
Copy link

k1LoW commented Mar 1, 2024

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 2manymws/rcutil#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.

  1. Provide a function that returns Items in reverse order to Cache.Range
    • Cache.RangeInReverse or Cache.Reverse ?
  2. 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant