Get List Of Cache Keys In Django
Solution 1:
For RedisCache you can get all available keys with.
from django.core.cacheimport cache
cache.keys('*')
Solution 2:
As mentioned there is no way to get a list of all cache keys within django. If you're using an external cache (e.g. memcached, or database caching) you can inspect the external cache directly.
But if you want to know how to convert a django key to the one used in the backend system, django's make_key() function will do this.
https://docs.djangoproject.com/en/1.8/topics/cache/#cache-key-transformation
>>> from django.core.cache import caches
>>> caches['default'].make_key('test-key')
u':1:test-key'
Solution 3:
You can use http://www.darkcoding.net/software/memcached-list-all-keys/ as explained in How do I check the content of a Django cache with Python memcached?
Solution 4:
Switch to using LocMemCache instead of MemcachedCache:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'unique-snowflake',
}
}
Then see the question Contents of locmem cache in Django?:
from django.core.cache.backends import locmem
print(locmem._caches)
Solution 5:
You can use memcached_stats from: https://github.com/dlrust/python-memcached-stats. This package makes it possible to view the memcached keys from within the python environment.
Post a Comment for "Get List Of Cache Keys In Django"