Login

Expire page from cache

Author:
mattgrayson
Posted:
August 1, 2008
Language:
Python
Version:
.96
Tags:
cache caching expiration
Score:
7 (after 7 ratings)

A simple helper function that clears the cache for a given URL, assuming no headers. Probably best used when wired up to a model's post_save event via signals. See message to django-users mailing list for background.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from django.core.cache import cache
from django.http import HttpRequest
from django.utils.cache import get_cache_key

def expire_page(path):
    request = HttpRequest()
    request.path = path
    key = get_cache_key(request)
    if cache.has_key(key):   
        cache.delete(key)

More like this

  1. cache_smart template tag by michiel_1981 7 years, 5 months ago
  2. New view decorator to only cache pages for anonymous users by vaughnkoch 4 years, 9 months ago
  3. Clean up expired django.contrib.session's in a huge MySQL InnoDB table by patsplat 6 years, 7 months ago
  4. MintCache by gfranxman 8 years, 4 months ago
  5. Conditional cache decorator by alexisbellido 2 years, 11 months ago

Comments

Please login first before commenting.