why memcache can cache django model

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

你可能感兴趣的:(数据库,django,cache,memcached,Numbers,Types)