aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Austin <chad@imvu.com>2013-01-30 16:43:29 -0800
committerChad Austin <chad@imvu.com>2013-03-04 19:23:52 -0800
commit8e63a929d4fe38d8929bc383a433199cba00555d (patch)
tree3b402a561c7f4663df2620f3a5b94df47e233f13
parentd0423ad1cc42fd552472c94aaf26410e7a7b73b8 (diff)
Work towards making JCache an object
-rw-r--r--tools/shared.py32
1 files changed, 16 insertions, 16 deletions
diff --git a/tools/shared.py b/tools/shared.py
index afb80abf..5383979c 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -1281,11 +1281,11 @@ class Cache:
class JCache:
dirname = os.path.join(Cache.dirname, 'jcache')
- @staticmethod
- def ensure():
+ @classmethod
+ def ensure(self):
Cache.ensure()
- if not os.path.exists(JCache.dirname):
- os.makedirs(JCache.dirname)
+ if not os.path.exists(self.dirname):
+ os.makedirs(self.dirname)
@staticmethod
def get_shortkey(keys):
@@ -1297,15 +1297,15 @@ class JCache:
ret += hashlib.md5(key).hexdigest()
return ret
- @staticmethod
- def get_cachename(shortkey):
- return os.path.join(JCache.dirname, shortkey)
+ @classmethod
+ def get_cachename(self, shortkey):
+ return os.path.join(self.dirname, shortkey)
# Returns a cached value, if it exists. Make sure the full key matches
- @staticmethod
- def get(shortkey, keys):
+ @classmethod
+ def get(self, shortkey, keys):
if DEBUG_CACHE: print >> sys.stderr, 'jcache get?', shortkey
- cachename = JCache.get_cachename(shortkey)
+ cachename = self.get_cachename(shortkey)
if not os.path.exists(cachename):
if DEBUG_CACHE: print >> sys.stderr, 'jcache none at all'
return
@@ -1329,10 +1329,10 @@ class JCache:
return data[1]
# Sets the cached value for a key (from get_key)
- @staticmethod
- def set(shortkey, keys, value):
+ @classmethod
+ def set(self, shortkey, keys, value):
if DEBUG_CACHE: print >> sys.stderr, 'save to cache', shortkey
- cachename = JCache.get_cachename(shortkey)
+ cachename = self.get_cachename(shortkey)
try:
f = open(cachename, 'w')
f.write(zlib.compress(cPickle.dumps([keys, value])))
@@ -1353,11 +1353,11 @@ class JCache:
# generate the same chunks, barring big differences in function sizes that
# violate our chunk size guideline. If caching is not used, chunking_file
# should be None
- @staticmethod
- def chunkify(funcs, chunk_size, chunking_file):
+ @classmethod
+ def chunkify(self, funcs, chunk_size, chunking_file):
previous_mapping = None
if chunking_file:
- chunking_file = JCache.get_cachename(chunking_file)
+ chunking_file = self.get_cachename(chunking_file)
if os.path.exists(chunking_file):
try:
previous_mapping = cPickle.Unpickler(open(chunking_file, 'rb')).load() # maps a function identifier to the chunk number it will be in