Commits

Anonymous committed 1c9b89f

* Fixed bug whereby CacheManager.invalidate wouldn't work for a function
decorated by cache.cache(). (#61)

Comments (0)

Files changed (3)

 * Added an optimization to the FileNamespaceContainer when used with 
   Session, such that the pickled contents of the file are not 
   read a second time when session.save() is called.  (#64)
+* Fixed bug whereby CacheManager.invalidate wouldn't work for a function
+  decorated by cache.cache(). (#61)
 
 Release 1.5.4 (6/16/2010)
 =========================
 
         """
         cache = [None]
-        key = " ".join(str(x) for x in args)
+        cache_args = [str(x) for x in args]
 
         def decorate(func):
             namespace = util.func_namespace(func)
             def cached(*args):
                 if not cache[0]:
                     cache[0] = self.get_cache(namespace, **kwargs)
-                cache_key = key + " " + " ".join(str(x) for x in args)
+                cache_key = " ".join(cache_args + [str(x) for x in args])
                 def go():
                     return func(*args)
                 return cache[0].get_value(cache_key, createfunc=go)

tests/test_cache_decorator.py

     cache = CacheManager(**parse_cache_config_options(opts))
     return cache
 
+def make_cached_func(**opts):
+    cache = make_cache_obj(**opts)
+    @cache.cache()
+    def load(person):
+        now = datetime.now()
+        return "Hi there %s, its currently %s" % (person, now)
+    return cache, load
+
 def make_region_cached_func():
     opts = {}
     opts['cache.regions'] = 'short_term, long_term'
         return "Hi there %s, its currently %s" % (person, now)
     return load_person
 
-def test_check_decorator():
+def test_check_region_decorator():
     func = make_region_cached_func()
     result = func('Fred')
     assert 'Fred' in result
     # Invalidate a non-existent key
     region_invalidate(func, None, 'Fredd')
     assert result3 == result2
+
+def test_invalidate_cache():
+    cache, func = make_cached_func()
+    val = func('foo')
+    time.sleep(.1)
+    val2 = func('foo')
+    assert val == val2
+
+    cache.invalidate(func, 'foo')
+    val3 = func('foo')
+    assert val3 != val