From 20d80dee61ac6d341e46472cc77220e5a65d8846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 30 Jan 2018 18:19:58 +0100 Subject: [PATCH] cache_for_request should take function itself into account too Previously it only looked at the arguments to the function, but not the function itself. --- pillar/web/utils/caching.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pillar/web/utils/caching.py b/pillar/web/utils/caching.py index 749f3154..92e055fd 100644 --- a/pillar/web/utils/caching.py +++ b/pillar/web/utils/caching.py @@ -1,3 +1,4 @@ +import collections import functools from flask import g @@ -13,13 +14,13 @@ def cache_for_request(): @functools.wraps(func) def wrapper(*args, **kwargs): if not hasattr(g, 'request_level_cache'): - g.request_level_cache = {} + g.request_level_cache = collections.defaultdict(dict) try: - return g.request_level_cache[args] + return g.request_level_cache[func][args] except KeyError: val = func(*args, **kwargs) - g.request_level_cache[args] = val + g.request_level_cache[func][args] = val return val return wrapper return decorator