File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 55import socket
66from functools import wraps
77
8+ try :
9+ import cPickle as pickle
10+ except ImportError :
11+ import pickle
12+
813from django .core .cache import InvalidCacheBackendError
914from django .core .cache .backends .memcached import BaseMemcachedCache
1015
1520logger = logging .getLogger (__name__ )
1621
1722
23+ def serialize_pickle (key , value ):
24+ if isinstance (value , str ):
25+ return value , 1
26+ return pickle .dumps (value ), 2
27+
28+
29+ def deserialize_pickle (key , value , flags ):
30+ if flags == 1 :
31+ return value
32+ if flags == 2 :
33+ return pickle .loads (value )
34+
35+
1836def invalidate_cache_after_error (f ):
1937 """
2038 catch any exception and invalidate internal cache with list of nodes
@@ -83,6 +101,8 @@ def _cache(self):
83101 if getattr (self , '_client' , None ) is None :
84102
85103 options = self ._options
104+ options ['serializer' ] = serialize_pickle
105+ options ['deserializer' ] = deserialize_pickle
86106 options .setdefault ('ignore_exc' , True )
87107 options .pop ('cluster_timeout' , None )
88108
You can’t perform that action at this time.
0 commit comments