Registers size-aware-lfu eviction policy - #13
Open
shubham-dce wants to merge 1 commit into
Open
Conversation
Owner
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced Aug 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Motivation
Currently diskcache does not provide any choice for selection size-based eviction policy. There is chance that though the
_cull()method runs inside theset()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 thatare 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_POLICYChanges
size-aware-lfupolicy to theEVICITION_POLICYdictionary in core.pyaccess_countwith the same name as least-frequently-used. Completely safe to reuse the name, since it containsIF NOT EXISTSthat provides idempotent behavior. Also safe even the policy changes mid-program.cullset toNonehere, the mechanism deferred for this PR. It still removes the expired keys in theset()method.Testing