Get list of Cache Keys in Django

前端 未结 8 2048
暗喜
暗喜 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:37

    If this is not too out of date, I have had similar issue, due I have had to iterate over whole cache. I managed it, when I add something to my cache like in following pseudocode:

    #create caches key list if not exists
    if not my_cache.get("keys"):
        my_cache.set("keys", [])
    
    #add to my cache
    my_cache.set(key, value)
    
    #add key to keys
    if key not in my_cache.get("keys"):
        keys_list = my_cache.get("keys")
        keys_list.append(key)
        my_cache.set("keys", keys_list)
    

提交回复
热议问题