Draft
Conversation
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.
All submissions
RefreshableSessionobject.'--no-verify|-nvarguments will not help you avoid the status checks!git commit, runpre-commit installandpre-commit install-hooksbeforehand.New feature submissions
sphinx-build doc doc/_buildfrom the root directory?export ROLE_ARN=<your role arn here>.Submission details
Implements #109
In the true spirit of Cunningham, I present a change that technically works. At the time of writing, this PR adds an implementation of a Least Frequently Used cache eviction strategy. It does so in a way that adds a lot of implementation complexity, because I definitely didn't nail the abstraction.
Shall we dig in?
BaseCacheBaseCacheis an ABC that implements a generalized version of the dunder methods fromClientCache. Notably, these dunder methods call the equivalent public methods instead of interacting directly withself._cache(for example,__getitem__(self, key)callsself.get(key)) so strategy-specific logic is contained in subclass implementations. The class also defines abstract methods for all of the public methods that will be implemented on subclasses. Lastly, it has a staticnew()method that takesmax_sizeandstrategyarguments and returns an instance of the appropriate subclass based onstrategy.The underlying data structure for the cache is a plain dict, previously an
OrderedDict. I'm not sure if this was the right decision, but I'm fairly pleased with the outcome. The new LFU strategy requires more tracking thanOrderedDictprovides, and the LFU tracking data structure can also be used for LRU tracking. I decided to share the same components for both strategies. One significant complexity tradeoff is that this requires adding a layer of indirection to cache values to carry a reference to the value's "tracking node". More on that later.LRUClientCacheLRUClientCacheinherits fromBaseCacheand implements all of its abstract methods. These methods are (or should be) equivalent to the currentClientCache.[to be continued...]