Clear Django Cache

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from django.core.cache import cache
try:
	cache._cache.clear()	# in-memory caching
except AttributeError:
	# try filesystem caching next
	old = cache._cull_frequency
	old_max = cache._max_entries
	cache._max_entries = 0
	cache._cull_frequency = 1
	cache._cull()
	cache._cull_frequency = old
	cache._max_entries = old_max

More like this

  1. Expire page from cache by mattgrayson 3 years, 6 months ago
  2. Template tag to clear cached template fragment by joao.coelho 2 years, 2 months ago
  3. cleat_list by Tomek 1 year, 1 month ago
  4. clear session table by rubic 4 years, 11 months ago
  5. Cache Decorator by ericmoritz 3 years, 2 months ago

Comments

diefenbach (on January 20, 2009):

At least for locmem one has to do clear also "_expire_info", otherwise there will be key errors:

cache._expire_info.clear()

#

ofri (on May 3, 2009):

if you're using memcached it's

 cache._cache.flush_all()

#

(Forgotten your password?)