- Author:
- ericmoritz
- Posted:
- December 9, 2008
- Language:
- Python
- Version:
- 1.0
- Score:
- 4 (after 4 ratings)
A cache decorator.
1 2 3 4 5 6 7 8 | def cache_result(callable, cache_key, timeout):
def inner(*args, **kwargs):
result = cache.get(cache_key)
if result is None:
result = callable(*args, **kwargs)
cache.set(cache_key, result, timeout)
return result
return inner
|
More like this
- Form field with fixed value by roam 5 days, 1 hour ago
- New Snippet! by Antoliny0919 1 week, 4 days ago
- Add Toggle Switch Widget to Django Forms by OgliariNatan 3 months ago
- get_object_or_none by azwdevops 6 months, 3 weeks ago
- Mask sensitive data from logger by agusmakmun 8 months, 2 weeks ago
Comments
Please login first before commenting.