in clay/http.py [0:0]
def cache_control(**cache_options):
'''
Decorator that adds a Cache-Control header to the response returned from a
view. Each keyword argument to this decorator is an option to be appended
to the Cache-Control header. Underscores '_' are replaced with dashes '-'
and boolean values are assumed to be directives.
Examples:
@cache_control(max_age=0, no_cache=True)
@cache_control(max_age=3600, public=True)
'''
def decorator(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
response = make_response(f(*args, **kwargs))
cache_control = []
for key, value in six.iteritems(cache_options):
key = key.replace('_', '-')
if isinstance(value, bool):
cache_control.append(key)
elif isinstance(value, six.string_types):
cache_control.append('%s="%s"' % (key, value))
else:
cache_control.append('%s=%s' % (key, value))
cache_control = ', '.join(cache_control)
response.headers['Cache-Control'] = cache_control
return response
return wrapper
return decorator