summary refs log tree commit diff
path: root/synapse/util
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-08-12 16:42:46 +0100
committerErik Johnston <erik@matrix.org>2015-08-12 16:42:46 +0100
commitcfa62007a392a2d6da818a45999c71da44a6da12 (patch)
treeba8f34c4968f3cc52a7b56fa73c8512d2ec9d7f8 /synapse/util
parentSimplify staggered deferred lists (diff)
downloadsynapse-cfa62007a392a2d6da818a45999c71da44a6da12.tar.xz
Docstring
Diffstat (limited to 'synapse/util')
-rw-r--r--synapse/util/caches/descriptors.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/synapse/util/caches/descriptors.py b/synapse/util/caches/descriptors.py
index 408c3b5e65..83bfec2f02 100644
--- a/synapse/util/caches/descriptors.py
+++ b/synapse/util/caches/descriptors.py
@@ -341,6 +341,33 @@ def cachedInlineCallbacks(max_entries=1000, num_args=1, lru=False):
 
 
 def cachedList(cache, list_name, num_args=1, inlineCallbacks=False):
+    """Creates a descriptor that wraps a function in a `CacheListDescriptor`.
+
+    Used to do batch lookups for an already created cache. A single argument
+    is specified as a list that is iterated through to lookup keys in the
+    original cache. A new list consisting of the keys that weren't in the cache
+    get passed to the original function, the result of which is stored in the
+    cache.
+
+    Args:
+        cache (Cache): The underlying cache to use.
+        list_name (str): The name of the argument that is the list to use to
+            do batch lookups in the cache.
+        num_args (int): Number of arguments to use as the key in the cache.
+        inlineCallbacks (bool): Should the function be wrapped in an
+            `defer.inlineCallbacks`?
+
+    Example:
+
+        class Example(object):
+            @cached(num_args=2)
+            def do_something(self, first_arg):
+                ...
+
+            @cachedList(do_something.cache, list_name="second_args", num_args=2)
+            def batch_do_something(self, first_arg, second_args):
+                ...
+    """
     return lambda orig: CacheListDescriptor(
         orig,
         cache=cache,