We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 645fc33 commit afdab20Copy full SHA for afdab20
flask_apidoc/utils.py
@@ -2,22 +2,22 @@
2
Helpers.
3
"""
4
5
+import functools
6
+
7
8
def cached(f):
9
10
Cache decorator for functions taking one or more arguments.
11
:param f: The function to be cached.
12
:return: The cached value.
13
- class CachedDict(dict):
- def __init__(self, f):
14
- self.f = f
15
-
16
- def __call__(self, *args):
17
- return self[args]
18
19
- def __missing__(self, key):
20
- ret = self[key] = self.f(*key)
21
- return ret
+ cache = f.cache = {}
22
23
- return CachedDict(f)
+ @functools.wraps(f)
+ def decorator(*args, **kwargs):
+ key = str(args) + str(kwargs)
+ if key not in cache:
+ cache[key] = f(*args, **kwargs)
+ return cache[key]
+ return decorator
0 commit comments