Write a flask-restful version of cache-control. Remove the comments to add back in post methods.
This commit is contained in:
parent
60015f0ae0
commit
092e236694
4 changed files with 18 additions and 5 deletions
|
@ -1,4 +1,5 @@
|
|||
from functools import wraps
|
||||
from flask.ext.restful.utils import unpack
|
||||
|
||||
|
||||
def cache_control(max_age=55):
|
||||
|
@ -12,6 +13,18 @@ def cache_control(max_age=55):
|
|||
return wrap
|
||||
|
||||
|
||||
def cache_control_flask_restful(max_age=55):
|
||||
def wrap(f):
|
||||
@wraps(f)
|
||||
def add_max_age(*args, **kwargs):
|
||||
response = f(*args, **kwargs)
|
||||
body, status_code, headers = unpack(response)
|
||||
headers['Cache-Control'] = 'max-age=%d' % max_age
|
||||
return body, status_code, headers
|
||||
return add_max_age
|
||||
return wrap
|
||||
|
||||
|
||||
def no_cache(f):
|
||||
@wraps(f)
|
||||
def add_no_cache(*args, **kwargs):
|
||||
|
|
Reference in a new issue