Fix cache management.
authorNeal H. Walfield <neal@walfield.org>
Wed, 14 Sep 2011 12:30:44 +0000 (14:30 +0200)
committerNeal H. Walfield <neal@walfield.org>
Wed, 14 Sep 2011 12:30:44 +0000 (14:30 +0200)
 - After determining that the cache is invalid, actually rebuild it.

src/rss_sqlite.py

index 077fce0..2e96225 100644 (file)
@@ -139,7 +139,9 @@ class BaseObject(object):
             cache = self.cache[table]
 
             if time.time() - cache[None] > 60:
-                self.cache[table].clear()
+                # logger.debug("%s: Cache too old: clearing" % (table,))
+                del self.cache[table]
+                cache = None
         except KeyError:
             cache = None
 
@@ -148,6 +150,8 @@ class BaseObject(object):
             # The cache is empty or the caller wants a column that we
             # don't cache.
             if (table, column) in self.cached_columns:
+                # logger.debug("%s: Rebuilding cache" % (table,))
+
                 do_cache = True
 
                 self.cache[table] = cache = {}
@@ -193,10 +197,13 @@ class BaseObject(object):
 
         try:
             if id is not None:
-                return cache[column][id]
+                value = cache[column][id]
+                # logger.debug("%s.%s:%s -> %s" % (table, column, id, value))
+                return value
             else:
                 return cache[column].values()
         except KeyError:
+            # logger.debug("%s.%s:%s -> Not found" % (table, column, id))
             return None
 
 class Feed(BaseObject):