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.
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user