I don't want to restart the memcached server!
Asked
Active
Viewed 1.4k times
3 Answers
42
from django.core.cache import cache
cache._cache.flush_all()
Also see this ticket, it has a patch (that I haven't tested) to flush any type of cache backend: http://code.djangoproject.com/ticket/11503
-
2For anyone who needs it, the cache lib is located in django.core.cache. So to run the command above, you need to import cache from django.core.cache import cache – kayluhb Aug 31 '12 at 14:46
-
I have `CACHE_MIDDLEWARE_ALIAS` pointing to a nondefault `memcached` cache but the command still tries to clear `default` and fails with `AttributeError: 'FileBasedCache' object has no attribute '_cache'` – int_ua Mar 23 '15 at 09:10
-
2These days, you can use `from django.core.cache import cache; cache.clear()` – Shadow Jul 29 '15 at 03:39
2
And an one-liner from console:
echo "from django.core.cache import cache; cache._cache.flush_all()" | ./manage.py shell [--settings=myapp.settings_live]

Wtower
- 18,848
- 11
- 103
- 80