Skip to content
This repository has been archived by the owner on Dec 26, 2020. It is now read-only.

Commit

Permalink
Adding caching helper
Browse files Browse the repository at this point in the history
  • Loading branch information
swaroopch committed May 7, 2011
1 parent 0b6f215 commit c860f30
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions flask_application/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

import datetime
import math
from functools import wraps

# Caching
def cached(app, timeout=5 * 60, key='view/%s'):
'''http://flask.pocoo.org/docs/patterns/viewdecorators/#caching-decorator'''
def decorator(f):
@wraps(f)
def decorated_function(*args, **kwargs):
cache_key = key % request.path
rv = app.cache.get(cache_key)
if rv is not None:
return rv
rv = f(*args, **kwargs)
app.cache.set(cache_key, rv, timeout=timeout)
return rv
return decorated_function
return decorator


# Custom Template Filters
def datetimeformat(value):
Expand Down

0 comments on commit c860f30

Please sign in to comment.