Page Menu
Home
Search
Configure Global Search
Log In
Files
F13095270
caching.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
703 B
Subscribers
None
caching.py
View Options
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
Details
Attached
Mime Type
text/x-python
Expires
Sun, May 22, 7:27 PM (2 d)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
46/56/b363807d00bac4a889cc2f3345c9
Attached To
rPS Pillar
Event Timeline
Log In to Comment