diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-03-05 10:18:14 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-03-05 10:18:14 -0800 |
commit | 46158be251798bf66417b1ce891ccf2e29e2ec85 (patch) | |
tree | 8c41a4357112a3ad7672abd19a4784ba150c3ea2 /tools/cache.py | |
parent | ce09c386442cefacad53b849347c12411c5d3930 (diff) |
restore jcache compression, busted by pull #826
Diffstat (limited to 'tools/cache.py')
-rw-r--r-- | tools/cache.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/tools/cache.py b/tools/cache.py index 6647219d..a63d7bb3 100644 --- a/tools/cache.py +++ b/tools/cache.py @@ -1,4 +1,4 @@ -import os.path, shutil, hashlib, cPickle +import os.path, shutil, hashlib, cPickle, zlib import tempfiles @@ -68,7 +68,10 @@ class JCache: if not os.path.exists(cachename): #if DEBUG: print >> sys.stderr, 'jcache none at all' return - data = cPickle.Unpickler(open(cachename, 'rb')).load() + try: + data = cPickle.loads(zlib.decompress(open(cachename).read())) + except Exception, e: + if DEBUG_CACHE: print >> sys.stderr, 'jcache decompress/unpickle error:', e if len(data) != 2: #if DEBUG: print >> sys.stderr, 'jcache error in get' return @@ -86,7 +89,13 @@ class JCache: # Sets the cached value for a key (from get_key) def set(self, shortkey, keys, value): cachename = self.get_cachename(shortkey) - cPickle.Pickler(open(cachename, 'wb')).dump([keys, value]) + try: + f = open(cachename, 'w') + f.write(zlib.compress(cPickle.dumps([keys, value]))) + f.close() + except Exception, e: + if DEBUG_CACHE: print >> sys.stderr, 'jcache compress/pickle error:', e + return #if DEBUG: # for i in range(len(keys)): # open(cachename + '.key' + str(i), 'w').write(keys[i]) |