django-cache-memoize
django-cache-memoize copied to clipboard
Why _refresh and invalidate doesn't work?
I'm using this package in django,like this:
class A(models.Model):
@cache_memoize(300)
def b(self, arg1='', arg2=None)
return ...
And clear cache like this:
self.b(_refresh=True)
self.b.invalidate(self)
Both this two method can't clear the method b's cache.
I found that when you call the method b with _refresh,you must not use the position parameter name.
Your example doesn't have any function decorated with @cache_memoize()
...
I'm sorry,it's my mistake.
Now the question is that,When I want to clear the cache,I must call the method with _refresh=True
without positional arg name,like this:
self.b('', None, _refresh=True)
if call this method with positional arg name, the clear will not work.Like this:
self.b(arg1='', arg2=None, _refresh=True)
And how can I clear a function's cache by all args?Like function b's arg1 equals 1,2,3,4,and so on, and arg2 equals '1', '2', and so on.
Since you had said that at readme:
There is no way to clear more than one cache key. In the above example, you had to know the "original arguments" when you wanted to invalidate the cache. There is no method "search" for all cache keys that match a certain pattern.
But I also want to what can I do to practice this.
if call this method with positional arg name, the clear will not work
Correct. The invalidation signature needs to the exact same way as the non-invalidation signature.
But I also want to what can I do to practice this.
Practice? Can you try to phrase yourself differently?
I'm sorry.What I mean is that how can I clear all cache of a function.Do you have any advise?
With the current implementation, there's no way to clear all cache for a function, unless you specify a custom prefix
and change it every time you need to clear the cache.