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

Add a simple eviction policy to enforce limits with low memory overhead #303

Closed
whitfin opened this issue Nov 23, 2022 · 0 comments · Fixed by #306
Closed

Add a simple eviction policy to enforce limits with low memory overhead #303

whitfin opened this issue Nov 23, 2022 · 0 comments · Fixed by #306
Assignees
Milestone

Comments

@whitfin
Copy link
Owner

whitfin commented Nov 23, 2022

This was sort of raised in #300, but it's something I've been wanting to do for a while.

Right now there is an LRW eviction policy, which acts as an evented system for pruning records when the cache is too large. As such it's extremely accurate on keeping the cache below bounds. This comes at a cost of message passing (as it acts as a hook).

We can provide the same, except that it runs on a timer instead of acting as a hook. This will be less accurate, but there will be far lower memory used by the actual policy. You are effectively trading lower policy memory for potential bursts in memory as your cache goes over the limit.

It is important to document the difference between the hooks, and their tradeoffs. I'm not sure how to name the new policies, perhaps we have Cachex.Policy.LRW.Evented and Cachex.Policy.LRW.Timed, and we alias Cachex.Policy.LRW through to the evented version (so we can ship this in a minor version bump).

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

Successfully merging a pull request may close this issue.

1 participant