Mike Bayer avatar Mike Bayer committed b158fcb

- rename cache_for() to set()
- changelog
- also had the "change" directive wrong in changelog
- test for decorated_fn.set() wasn't looking for correct assertion?

Comments (0)

Files changed (3)

docs/build/changelog.rst

 .. changelog::
     :version: 0.4.1
 
-    .. change:
+    .. change::
+        :tags: feature
+        :pullreq: 9
+
+      The function decorated by :meth:`.Region.cache_on_arguments`
+      now includes a ``set()`` method, in addition to the existing
+      ``invalidate()`` method.   Like ``invalidate()``, it accepts
+      a set of function arguments, but additionally accepts as the
+      first positional argument a new value to place in the cache,
+      to take the place of that key.  Courtesy Antoine Bertin.
+
+    .. change::
         :tags: bug
         :tickets: 15
 
       during the "write" operation, the file lock, if enabled,
       would not be released, thereby deadlocking the app.
 
-    .. change:
+    .. change::
         :tags: bug
         :tickets: 12
 
       key_mangler is still needed if actual unicode arguments
       are being used by the decorated function, however.
 
-    .. change:
+    .. change::
         :tags: feature
 
       Redis backend now accepts optional "url" argument,
       method to determine connection info.  Courtesy
       Jon Rosebaugh.
 
-    .. change:
+    .. change::
         :tags: feature
 
       Redis backend now accepts optional "password"
       argument.  Courtesy Jon Rosebaugh.
 
-    .. change:
+    .. change::
         :tags: feature
 
       DBM backend has "fallback" when calling dbm.get() to

dogpile/cache/region.py

 
             generate_something.invalidate(5, 6)
 
-        Another attribute ``cache_for`` is added to provide extra caching
+        Another attribute ``set`` is added to provide extra caching
         possibilities within the function. This is a convenience method for
         :meth:`.CacheRegion.set` with the same key generator as it would
-        have been by using ``cache_on_arguments``. Pass to ``cache_for()``
+        have been by using ``cache_on_arguments``. Pass to ``set()``
         the same arguments you'd pass to the function itself and an extra
         argument ``value`` at the begining that contains the value to cache::
 
-            generate_something.cache_for(3, 5, 6)
+            generate_something.set(3, 5, 6)
 
         The default key generation will use the name
         of the function, the module name for the function,
                 key = key_generator(*arg, **kw)
                 self.delete(key)
 
-            def cache_for(value, *arg, **kw):
+            def set_(value, *arg, **kw):
                 key = key_generator(*arg, **kw)
                 self.set(key, value)
 
-            decorate.cache_for = cache_for
+            decorate.set = set_
             decorate.invalidate = invalidate
 
             return decorate

tests/cache/test_decorator.py

         reg = self._region(config_args={"expiration_time":.25})
 
         counter = [0]
-        @reg.cache_on_arguments(namespace=namespace, 
+        @reg.cache_on_arguments(namespace=namespace,
                             expiration_time=expiration_time)
         def go(a, b):
             counter[0] +=1
     def test_explicit_set(self):
         go = self._fixture(expiration_time=1)
         eq_(go(1, 2), (1, 1, 2))
-        go.cache_for(5, 1, 2)
+        go.set(5, 1, 2)
         eq_(go(3, 4), (2, 3, 4))
-        eq_(go(1, 2), (5, 1, 2))
+        eq_(go(1, 2), 5)
         go.invalidate(1, 2)
         eq_(go(1, 2), (3, 1, 2))
-        go.cache_for(0, 1, 3)
-        eq_(go(1, 3), (0, 1, 3))
+        go.set(0, 1, 3)
+        eq_(go(1, 3), 0)
 
 class KeyGenerationTest(TestCase):
     def _keygen_decorator(self, namespace=None):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.