Sebastian Hanula avatar Sebastian Hanula committed eea0cda

Added function_multi_key_generator keyword argument to CacheRegion to allow customization of key generator in CacheRegion.cache_multi_on_arguments().

Comments (0)

Files changed (1)


                         [kw[k] for k in namespace] +
                         [str(x) for x in arg]
+            return generate_key
      Where the decorator might be used as::
         @my_region.cache_on_arguments(namespace=('x', 'y'))
         def my_function(a, b, **kw):
             return my_data()
+    :param function_multi_key_generator: Optional.
+     Similar to ``function_key_generator`` parameter, but it's used in
+     :meth:`.CacheRegion.cache_multi_on_arguments`. Generated function
+     should return list of keys. For example::
+        def my_multi_key_generator(namespace, fn):
+            namespace = fn.__name__ + (namespace or '')
+            def generate_keys(*args):
+                return [namespace + ':' + str(a) for a in args]
+            return generate_keys
     :param key_mangler: Function which will be used on all incoming
      keys before passing to the backend.  Defaults to ``None``,
     def __init__(self,
+            function_multi_key_generator=function_multi_key_generator,
         """Construct a new :class:`.CacheRegion`.""" = name
         self.function_key_generator = function_key_generator
+        self.function_multi_key_generator = function_multi_key_generator
         if key_mangler:
             self.key_mangler = key_mangler
         expiration_time_is_callable = compat.callable(expiration_time)
         def decorator(fn):
-            key_generator = function_multi_key_generator(namespace, fn)
+            key_generator = self.function_multi_key_generator(namespace, fn)
             def decorate(*arg, **kw):
                 cache_keys = arg
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
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.