Django(memcached)不缓存对象

2024-06-07 06:50:03 发布

您现在位置:Python中文网/ 问答频道 /正文

有人能解释一下为什么我要直接从django项目中使用memcached缓存后端?”管理.pyshell“没有返回我的图书对象b,而是没有返回?我的具体步骤是:

In [1]: from django.core.cache import cache

In [2]: key = 1234

In [3]: a = "test value"

In [4]: cache.set(key, a)

In [5]: print cache.get(key)
test value

In [6]: class Book():
   ...:     pages = 100
   ...:     

In [7]: b = Book()

In [8]: b.pages
Out[8]: 100

In [9]: key2 = 4321

In [10]: cache.set(key2, b)

In [11]: print cache.get(key2)
None

谢谢


Tags: 项目djangokeyintestcachegetvalue