Add caching support to catalog

We will now cache the results of the catalog for 60s and not hit the database at all if cached
This commit is contained in:
Joseph Schorr 2018-06-19 13:27:16 -04:00
parent a1c06042c6
commit 2caaf84f31
4 changed files with 53 additions and 10 deletions

View file

@ -4,5 +4,13 @@ class CacheKey(namedtuple('CacheKey', ['key', 'expiration'])):
""" Defines a key into the data model cache. """
pass
def for_repository_blob(namespace_name, repo_name, digest):
""" Returns a cache key for a blob in a repository. """
return CacheKey('repository_blob__%s_%s_%s' % (namespace_name, repo_name, digest), '60s')
def for_catalog_page(auth_context_key, start_id, limit):
""" Returns a cache key for a single page of a catalog lookup for an authed context. """
params = (auth_context_key or '(anon)', start_id or 0, limit or 0)
return CacheKey('catalog_page__%s_%s_%s' % params, '60s')