remove expired data
authorTony Mack <tmack@paris.CS.Princeton.EDU>
Sat, 29 Oct 2011 13:51:52 +0000 (09:51 -0400)
committerTony Mack <tmack@paris.CS.Princeton.EDU>
Sat, 29 Oct 2011 13:51:52 +0000 (09:51 -0400)
sfa/util/cache.py

index 0383ccc..a2ded4a 100644 (file)
@@ -82,9 +82,18 @@ class Cache:
            
     def get(self, key):
         data = self.cache.get(key)
-        if not data or data.is_expired():
-            return None 
-        return data.get_data()
+        if not data:  
+            data = None
+        elif data.is_expired():
+            self.pop(key)
+            data = None 
+        else:
+            data = data.get_data()
+        return data
+
+    def pop(self, key):
+        if key in self.cache:
+            self.cache.pop(key) 
 
     def dump(self):
         result = {}