Get list of Cache Keys in Django

Brenden picture Brenden · Jan 28, 2012 · Viewed 30.7k times · Source

I'm trying to understand how Django is setting keys for my views. I'm wondering if there's a way to just get all the saved keys from Memcached. something like a cache.all() or something. I've been trying to find the key with cache.has_key('test') but still cant figure out how the view keys are being named.

UPDATE: The reason I need this is because I need to manually delete parts of the cache but dont know the key values Django is setting for my cache_view key

Answer

Eduard Mukans picture Eduard Mukans · Apr 11, 2019

For RedisCache you can get all available keys with.

from django.core.cache import cache

cache.keys('*')