I set 4 cache values with LocMemCache as shown below:
from django.core.cache import cache
cache.set("first_name", "John")
cache.set("last_name", "Smith", version=2)
cache.set("age", 36, version=3)
cache.set("gender", "Male")
Then, I tried to see the contents of the cache with cache._cache
as shown below:
from django.core.cache import cache
print(cache._cache) # Here
But, the key's values contain b'\x80\x05\x95\x08\...
as shown below:
OrderedDict([(':1:gender', b'\x80\x05\x95\x08\x00\x00\x00\x00\x00\x00\x00\x8c\x04Male\x94.'), (':3:age', b'\x80\x05K$.'), (':2:last_name', b'\x80\x05\x95\t\x00\x00\x00\x00\x00\x00\x00\x8c\x05Smith\x94.'), (':1:first_name', b'\x80\x05\x95\x08\x00\x00\x00\x00\x00\x00\x00\x8c\x04John\x94.')])
Actually, the result which I expected is as shown below:
OrderedDict([(':1:gender', 'Male'), (':3:age', 36), (':2:last_name', 'Smith'), (':1:first_name', 'John')])
And, I tried to see the contents of the cache with cache._cache.items()
as shown below:
from django.core.cache import cache
print(cache._cache.items()) # Here
But again, the key's values contain b'\x80\x05\x95\x08\...
as shown below:
odict_items([(':1:gender', b'\x80\x05\x95\x08\x00\x00\x00\x00\x00\x00\x00\x8c\x04Male\x94.'), (':3:age', b'\x80\x05K$.'), (':2:last_name', b'\x80\x05\x95\t\x00\x00\x00\x00\x00\x00\x00\x8c\x05Smith\x94.'), (':1:first_name', b'\x80\x05\x95\x08\x00\x00\x00\x00\x00\x00\x00\x8c\x04John\x94.')])
Actually, the result which I expected is as shown below:
odict_items([(':1:gender', 'Male'), (':3:age', 36), (':2:last_name', 'Smith'), (':1:first_name', 'John')])
Lastly, I tried to see the contents of the cache with locmem._caches
as shown below:
from django.core.cache.backends import locmem
print(locmem._caches) # Here
But again, the key's values contain b'\x80\x05\x95\x08\...
as shown below:
{'': OrderedDict([(':1:gender', b'\x80\x05\x95\x08\x00\x00\x00\x00\x00\x00\x00\x8c\x04Male\x94.'), (':3:age', b'\x80\x05K$.'), (':2:last_name', b'\x80\x05\x95\t\x00\x00\x00\x00\x00\x00\x00\x8c\x05Smith\x94.'), (':1:first_name', b'\x80\x05\x95\x08\x00\x00\x00\x00\x00\x00\x00\x8c\x04John\x94.')])}
Actually, the result which I expected is as shown below:
{'': OrderedDict([(':1:gender', 'Male'), (':3:age', 36), (':2:last_name', 'Smith'), (':1:first_name', 'John')])}
My questions:
- How can I get the contents of the cache properly in Django?
- What is
b'\x80\x05\x95\x08\...
?
b'\x80\x05\x95\x08\...
denotes the pickled representation of an object – Plosive