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

Automatically (with help) invalidate cache when code changes #35

Open
jdavid opened this issue Aug 28, 2019 · 5 comments
Open

Automatically (with help) invalidate cache when code changes #35

jdavid opened this issue Aug 28, 2019 · 5 comments

Comments

@jdavid
Copy link

jdavid commented Aug 28, 2019

Sometimes a change in the code should trigger the invalidation of the cache. The idea is to add the version optional parameter to cache_memoize, defaulting to None. Then the version, if not None, would be added to the cache key.

We could use it like this:

@cache_memoize(60)
def f(...):

Then we fix a bug in f and write:

@cache_memoize(60, version=1)

Another bug fixed (so many 🐛 🪲 ) :

@cache_memoize(60, version=2) 

So, when the fixes are deployed the cache will be invalidated, instead of returning a wrong cached value.

@peterbe
Copy link
Owner

peterbe commented Aug 29, 2019

I like that. One could perhaps use it like this:

from gitutils import get_current_git_sha

current_git_sha = get_current_git_sha()

@cache_memoize(60, version=current_git_sha) 

@peterbe
Copy link
Owner

peterbe commented Aug 29, 2019

That would, if you chose to use it like that, mean that a fresh new deployment triggers a different cache key for all memoized functions.

@jdavid
Copy link
Author

jdavid commented Aug 30, 2019

Yes. It may be as well a more generic option (e.g. suffix), just something that is added to the key.

@pySilver
Copy link
Contributor

version / suffix would be nice, it can be set somewhere in project settings globally so if one really wants - all cache will be cleared when such option changes.

@utapyngo
Copy link

utapyngo commented Aug 30, 2021

I vote for version.

Django itself does support the version argument: https://docs.djangoproject.com/en/3.2/topics/cache/#cache-versioning

It should be easy to add just one more pass-through argument to cache_memoize.

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

No branches or pull requests

4 participants