- Author:
- girasquid
- Posted:
- September 23, 2008
- Language:
- Python
- Version:
- 1.0
- Score:
- 4 (after 4 ratings)
This piece of code will clear the cache, whether you are using in-memory or filesystem caching.
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
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
At least for locmem one has to do clear also "_expire_info", otherwise there will be key errors:
#
if you're using memcached it's
#
Please login first before commenting.