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

@ -719,6 +719,26 @@ def test_catalog(public_catalog, credentials, expected_repos, page_size, v2_prot
assert set(expected_repos).issubset(set(results))
def test_catalog_caching(v2_protocol, basic_images, liveserver_session, app_reloader,
liveserver, registry_server_executor):
""" Test: Calling the catalog after initially pulled will result in the catalog being cached. """
credentials = ('devtable', 'password')
# Conduct the initial catalog call to prime the cache.
results = v2_protocol.catalog(liveserver_session, credentials=credentials,
namespace='devtable', repo_name='simple')
token, _ = v2_protocol.auth(liveserver_session, credentials, 'devtable', 'simple')
# Disconnect the server from the database.
registry_server_executor.on(liveserver).break_database()
# Call the catalog again, which should now be cached.
cached_results = v2_protocol.catalog(liveserver_session, bearer_token=token)
assert len(cached_results) == len(results)
assert set(cached_results) == set(results)
@pytest.mark.parametrize('username, namespace, repository', [
('devtable', 'devtable', 'simple'),
('devtable', 'devtable', 'gargantuan'),