diff MoinMoin/caching.py @ 1638:5070d0358544

caching: move use_pickle to __init__, remove unused encode/decode args from .content()/.update()
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 22 Oct 2006 20:48:23 +0200
parents 47a173ae5401
children c0cb0884f7ec
line wrap: on
line diff
--- a/MoinMoin/caching.py	Sun Oct 22 20:31:37 2006 +0200
+++ b/MoinMoin/caching.py	Sun Oct 22 20:48:23 2006 +0200
@@ -31,7 +31,7 @@
     pass
 
 class CacheEntry:
-    def __init__(self, request, arena, key, scope='page_or_wiki', do_locking=True):
+    def __init__(self, request, arena, key, scope='page_or_wiki', do_locking=True, use_pickle=False):
         """ init a cache entry
             @param request: the request object
             @param arena: either a string or a page object, when we want to use
@@ -46,6 +46,7 @@
         self.request = request
         self.key = key
         self.locking = do_locking
+        self.use_pickle = use_pickle
         if scope == 'page_or_wiki': # XXX DEPRECATED, remove later
             if isinstance(arena, str):
                 self.arena_dir = os.path.join(request.cfg.cache_dir, request.cfg.siteid, arena)
@@ -118,13 +119,11 @@
         else:
             self.request.log("Can't acquire write lock in %s" % self.lock_dir)
 
-    def update(self, content, encode=False, use_pickle=False):
+    def update(self, content):
         try:
             tmpfname = self._tmpfilename()
             fname = self._filename()
-            if encode:
-                content = content.encode(config.charset)
-            elif use_pickle:
+            if self.use_pickle:
                 content = pickle.dumps(content, PICKLE_PROTOCOL)
             if not self.locking or self.locking and self.wlock.acquire(1.0):
                 try:
@@ -157,7 +156,7 @@
         else:
             self.request.log("Can't acquire write lock in %s" % self.lock_dir)
 
-    def content(self, decode=False, use_pickle=False):
+    def content(self):
         try:
             if not self.locking or self.locking and self.rlock.acquire(1.0):
                 try:
@@ -169,9 +168,7 @@
                         self.rlock.release()
             else:
                 self.request.log("Can't acquire read lock in %s" % self.lock_dir)
-            if decode:
-                data = data.decode(config.charset)
-            elif use_pickle:
+            if self.use_pickle:
                 data = pickle.loads(data)
             return data
         except (pickle.UnpicklingError, IOError, EOFError, ValueError), err: