Page MenuHome

caching.py
No OneTemporary

caching.py

import functools
from flask import g
def cache_for_request():
"""Decorator; caches the return value for the duration of the current request.
The caller determines the cache key: *args are used as cache key, **kwargs
are not.
"""
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
if not hasattr(g, 'request_level_cache'):
g.request_level_cache = {}
try:
return g.request_level_cache[args]
except KeyError:
val = func(*args, **kwargs)
g.request_level_cache[args] = val
return val
return wrapper
return decorator

File Metadata

Mime Type
text/x-python
Expires
Fri, Dec 4, 8:47 PM (1 d, 23 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
28/a1/58d0be81aa645c6ca1df79ef2f84

Event Timeline