Commits

Andriy Kornatskyy committed 56b051a

Added factory method to Cached to return initialized CacheDependency.

  • Participants
  • Parent commits 1f5cbfe

Comments (0)

Files changed (2)

File src/wheezy/caching/patterns.py

 from time import sleep
 from time import time
 
+from wheezy.caching.dependency import CacheDependency
+
 
 class Cached(object):
     """ Specializes access to cache by using a number of common settings
         """
         return self.cache.decr(key, delta, self.namespace, initial_value)
 
+    def dependency(self, master_key):
+        """ Returns an instance of `CacheDependency` initialized by
+            given *master_key*.
+        """
+        return CacheDependency(self.cache, master_key, self.time,
+                               self.namespace)
+
     def get_or_add(self, key, create_factory, dependency_factory):
         """ Cache Pattern: get an item by *key* from *cache* and
             if it is not available use *create_factory* to aquire one.

File src/wheezy/caching/tests/test_patterns.py

         self.cached.decr('key', 1, 0)
         self.mock_cache.decr.assert_called_once_with('key', 1, 'ns', 0)
 
+    def test_dependency(self):
+        """ Ensure returned CacheDependency is properly initialized.
+        """
+        d = self.cached.dependency('master_key')
+        assert self.cached.cache == d.cache
+        assert 'master_key' == d.master_key
+        assert self.cached.time == d.time
+        assert self.cached.namespace == d.namespace
+
 
 class OnePassTestCase(unittest.TestCase):