Skip to content

Registers size-aware-lfu eviction policy - #13

Open
shubham-dce wants to merge 1 commit into
masterfrom
eviction-01-policy-registration
Open

Registers size-aware-lfu eviction policy#13
shubham-dce wants to merge 1 commit into
masterfrom
eviction-01-policy-registration

Conversation

@shubham-dce

Copy link
Copy Markdown
Owner

Motivation

Currently diskcache does not provide any choice for selection size-based eviction policy. There is chance that though the _cull() method runs inside the set() but still the size is over the limit as the last added size was way more than that of the removed ones, and if this happens several times than the disk size will be occupied rapidly in a series of write operations. To avoid this situation, it needs a size based eviction policy, however it does not remove the items that
are frequently touched, this gives the shape to the size-aware-lfu policy, where lfu stands for least frequently used.

This PR targets to add this as an option for eviction policy, with minimal changes in the existing code.

Summary

Registers a new size-aware-lfu policy in the EVICTION_POLICY

Changes

  • Added size-aware-lfu policy to the EVICITION_POLICY dictionary in core.py
  • Creates index on the access_count with the same name as least-frequently-used. Completely safe to reuse the name, since it contains IF NOT EXISTS that provides idempotent behavior. Also safe even the policy changes mid-program.
  • cull set to None here, the mechanism deferred for this PR. It still removes the expired keys in the set() method.

Testing

  • Added 1 test to verify the registration of the eviction policy. Passes successfully.
  • Pre-existing tests passes successfully without any modification. Test coverage above 98%.

shubham-dce commented Aug 14, 2026

Copy link
Copy Markdown
Owner Author

@shubham-dce shubham-dce changed the title registers size-aware-lfu eviction policy Registers size-aware-lfu eviction policy Aug 14, 2026
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

Successfully merging this pull request may close these issues.

2 participants