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 scheduled LRW policy for low memory use #306

Merged
merged 5 commits into from
Jan 9, 2023
Merged

Add a scheduled LRW policy for low memory use #306

merged 5 commits into from
Jan 9, 2023

Conversation

whitfin
Copy link
Owner

@whitfin whitfin commented Jan 9, 2023

This closes #303 and #300.

This PR introduces a new implementation of the LRW policy which avoids the need for message passing in hooks. It operates on a (configurable) schedule to check the cache bounds. As such, it uses less memory but might have a larger delay on reclaiming space - pick your poison.

I moved Cachex.Policy.LRW into Cachex.Policy.LRW.Evented and delegated through to save the existing defaults, or people referencing that module already. The LRW logic stays inside Cachex.Policy.LRW, because it's used in both places. It will also be used if we ever get around to #305.

I think I want to change the default away from the evented version to the scheduled version, but I need to think more on this. Not only is the policy server more efficient, it will actually help throughput of your cache (because it's not pinging the LRW hook on every write). Given that the check is once per second, it seems like it should be hard to notice the change for most use cases.

I'm not sure I like enforce_bounds as a public name, so need to think about that. Even something like prune/2 might be better as a public name. I also removed some junk in the policy space which was unused in favour of just using hooks going forward. I originally had bigger plans, which is why the spec stuff was in there - but at this point I think it's just bloat.

@whitfin whitfin added this to the v3.5.0 milestone Jan 9, 2023
@whitfin whitfin self-assigned this Jan 9, 2023
@whitfin whitfin merged commit 7b4062b into main Jan 9, 2023
@whitfin whitfin deleted the issue-303 branch January 9, 2023 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a simple eviction policy to enforce limits with low memory overhead
1 participant