Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't delete cache for specific entry in Django
    primarykey
    data
    text
    <p>I'm trying to purge cache for one specific Entry when it is saved using signals.</p> <p>I'm using decorators (<code>signals</code> and <code>render_to</code>) from <a href="https://bitbucket.org/offline/django-annoying" rel="nofollow noreferrer"><code>django-annoying</code></a></p> <pre><code>@signals.post_save(sender=Artigo) def artigo_post_save(instance, **kwargs): from django.http import HttpRequest from django.utils.cache import get_cache_key from django.core.cache import cache # cache.delete(instance.get_absolute_url()) # not work request = HttpRequest() request.method = "GET" request.path = '/' + instance.get_absolute_url() print 'request path: ', request.path key = get_cache_key(request=request, key_prefix=settings.CACHE_MIDDLEWARE_KEY_PREFIX) print "found key" if cache.has_key(key) else "notfound key" if cache.has_key(key): cache.delete(key) cache.set(key, None, 0) </code></pre> <ul> <li>The problem is that when I save the model, I get output <code>"notfound key"</code>, so the cache continues without purge</li> <li><code>request.path</code> are point properly to my entry path.</li> </ul> <p>Some settings:</p> <pre><code>SESSION_ENGINE = "django.contrib.sessions.backends.cache" CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True CACHE_MIDDLEWARE_KEY_PREFIX = 'cache' CACHE_MIDDLEWARE_SECONDS = 600 CACHES = { 'default': { 'LOCATION': '', 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache' }, } </code></pre> <p>And the view:</p> <pre><code>@cache_page(60 * 60) @render_to('artigo.html') def artigo(request, categoria_slug, extra_slug="", artigo_slug=""): ... </code></pre> <p>Thank you.</p> <p><strong>EDIT:</strong><br> I did <a href="https://stackoverflow.com/a/10484328/1499847">Ilvar</a> changes and now i'm getting <code>"found key"</code> as return but I still can't delete cache:</p> <pre><code> key = _generate_cache_header_key(key_prefix=settings.CACHE_MIDDLEWARE_KEY_PREFIX, request=request) key = key.replace(settings.LANGUAGE_CODE, settings.LANGUAGES[0][0]) </code></pre> <p>Conf:</p> <pre><code>LANGUAGE_CODE = 'pt-BR' LANGUAGES = ( ('pt-BR','Portugues'), ) </code></pre> <ul> <li>I only have the content updated when I restart the Gevent Server.</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload