sqlalchemy / sqlalchemy/dogpile.cache
Make the Region Invalidation Strategy more flexible
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 299
- Forks
- 50
- PR merge metrics
- No merged PRs in 30d
Description
I have a use case where I can only determine if cache entry has expired by knowing the key and the time it was created.
As it stands the RegionInvalidationStrategy interface only receives the creation time.
If it was passed the key as well then I could implement the behaviour I need.
The use case is this:
I am querying the google analytics API, and caching the results in Redis. Although you can query for recent data, it is not guaranteed to be up to date.
The key is the datetime for the analytics data, I want to expire a cache entry if it was created less than a day after key (i.e it was recent data when it was created), but only if it is now more than an hour after it was created.
I have currently implemented this by overriding Region._is_cache_miss in a subclass. This is not great, because it only applies to the get_or_create class of methods, get_multi and get use self._unexpired_value_fn, which of course I could also override, but given RegionInvalidationStrategy is the proper way to manage invalidation I think it should be done there, and it also means it only has to be done in one place.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the RegionInvalidationStrategy interface and the Region methods mentioned in the issue: _is_cache_miss, _unexpired_value_fn, get_or_create, get_multi, and get. Trace how creation time reaches the strategy and compare the paths for each access method. Done means the strategy can use both the cache key and creation time consistently across those paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100