memcache 可以缓存一切可序列化和反序列化的对象
python-memcached使用pickle和cpickle来序列化和反序列化对象
而pickle可以序列化的类型有
The following types can be pickled:
- None, True, and False
- integers, long integers, floating point numbers, complex numbers
- normal and Unicode strings
- tuples, lists, sets, and dictionaries containing only picklable objects
- functions defined at the top level of a module
- built-in functions defined at the top level of a module
- classes that are defined at the top level of a module
- instances of such classes whose __dict__ or __setstate__() is picklable (see section The pickle protocol for details)
django model的__dict__除了各列内容就多一个'_state', 其只是用来保存数据库名的一个东西,so memcached can cache django model

本文介绍如何使用memcache缓存各种Python对象,包括Django模型实例。通过pickle和cpickle模块实现序列化与反序列化过程,使得memcache能够存储复杂的数据结构。文章详细列举了可被pickle处理的数据类型,并特别指出Django模型实例只需额外包含一个用于存储数据库状态的'_state'属性即可被缓存。
5038

被折叠的 条评论
为什么被折叠?



