Commits

zzzeek  committed 05b4d31

* cache.remove_value() removes the value even if it's already marked
'expired' (#42)

  • Participants
  • Parent commits 2aeced4

Comments (0)

Files changed (3)

 * file backend no longer squashes unpickling errors.   This was inconsistent
   behavior versus all the other backends.
 * invalidate_corrupt flag on Session now emits a warning. (#52)
+* cache.remove_value() removes the value even if it's already marked
+  'expired' (#42)
 
 Release 1.5.4 (6/16/2010)
 =========================

File beaker/cache.py

 
     def remove_value(self, key, **kw):
         mycontainer = self._get_value(key, **kw)
-        if mycontainer.has_current_value():
-            mycontainer.clear_value()
+        mycontainer.clear_value()
     remove = remove_value
 
     def _get_value(self, key, **kw):

File tests/test_cache.py

     x = cache.get_value('test', createfunc=lambda: 20, expiretime=2)
     assert x == 20
 
-
-
 def test_has_key_multicache():
     cache = Cache('test', data_dir='./cache', type='dbm')
     o = object()
     cache.remove_value(u'hiŏ')
     assert u'hiŏ' not in cache
 
+def test_remove_stale():
+    """test that remove_value() removes even if the value is expired."""
+
+    cache = Cache('test', type='memory')
+    o = object()
+    cache.namespace['key'] = (time.time() - 30, 10, o)
+    container = cache._get_value('key')
+    assert not container.has_current_value()
+    assert 'key' in container.namespace
+    cache.remove_value('key')
+    assert 'key' not in container.namespace
+
+    # safe to call again
+    cache.remove_value('key')
+
 def test_multi_keys():
     cache = Cache('newtests', data_dir='./cache', type='dbm')
     cache.clear()