why memcache can cache django model

来源:互联网 发布:php解析xml 编辑:程序博客网 时间:2024/06/02 18:25

memcache 可以缓存一切可序列化和反序列化的对象

python-memcached使用pickle和cpickle来序列化和反序列化对象

而pickle可以序列化的类型有

The following types can be pickled:

  • NoneTrue, 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