Add caching to the changes api since it is so expensive and can return large results.

This commit is contained in:
yackob03 2013-10-20 01:18:31 -04:00
parent c90602e48d
commit 13b457c440
2 changed files with 14 additions and 0 deletions

View file

@ -20,6 +20,7 @@ from auth.permissions import (ReadRepositoryPermission,
AdministerRepositoryPermission)
from endpoints import registry
from endpoints.web import common_login
from util.cache import cache_control
store = storage.load()
@ -380,6 +381,7 @@ def get_image(namespace, repository, image_id):
@app.route('/api/repository/<path:repository>/image/<image_id>/changes',
methods=['GET'])
@cache_control(max_age=60*60) # Cache for one hour
@parse_repository_name
def get_image_changes(namespace, repository, image_id):
permission = ReadRepositoryPermission(namespace, repository)

12
util/cache.py Normal file
View file

@ -0,0 +1,12 @@
from functools import wraps
def cache_control(max_age=55):
def wrap(f):
@wraps(f)
def add_max_age(*args, **kwargs):
response = f(*args, **kwargs)
response.headers['Cache-Control'] = 'max-age=%d' % max_age
return response
return add_max_age
return wrap