django-cache-memoize icon indicating copy to clipboard operation
django-cache-memoize copied to clipboard

Why _refresh and invalidate doesn't work?

Open wsf1990 opened this issue 5 years ago • 9 comments

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.

wsf1990 avatar Jun 11 '19 12:06 wsf1990

I found that when you call the method b with _refresh,you must not use the position parameter name.

wsf1990 avatar Jun 11 '19 14:06 wsf1990

Your example doesn't have any function decorated with @cache_memoize()...

akx avatar Jun 11 '19 14:06 akx

I'm sorry,it's my mistake.

wsf1990 avatar Jun 11 '19 14:06 wsf1990

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)

wsf1990 avatar Jun 12 '19 01:06 wsf1990

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.

wsf1990 avatar Jun 13 '19 09:06 wsf1990

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.

peterbe avatar Jun 18 '19 00:06 peterbe

But I also want to what can I do to practice this.

Practice? Can you try to phrase yourself differently?

peterbe avatar Jun 18 '19 00:06 peterbe

I'm sorry.What I mean is that how can I clear all cache of a function.Do you have any advise?

wsf1990 avatar Jun 20 '19 07:06 wsf1990

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.

akx avatar Jun 20 '19 19:06 akx