Get list of Cache Keys in Django

前端 未结 8 2086
暗喜
暗喜 2020-12-15 17:28

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 cac

8条回答
  •  清歌不尽
    2020-12-15 17:55

    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'
    

提交回复
热议问题