This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/data/cache/__init__.py

24 lines
861 B
Python
Raw Normal View History

2019-11-12 16:09:47 +00:00
from data.cache.impl import NoopDataModelCache, InMemoryDataModelCache, MemcachedModelCache
def get_model_cache(config):
""" Returns a data model cache matching the given configuration. """
cache_config = config.get('DATA_MODEL_CACHE_CONFIG', {})
engine = cache_config.get('engine', 'noop')
if engine == 'noop':
return NoopDataModelCache()
if engine == 'inmemory':
return InMemoryDataModelCache()
if engine == 'memcached':
endpoint = cache_config.get('endpoint', None)
if endpoint is None:
raise Exception('Missing `endpoint` for memcached model cache configuration')
timeout = cache_config.get('timeout')
connect_timeout = cache_config.get('connect_timeout')
return MemcachedModelCache(endpoint, timeout=timeout, connect_timeout=connect_timeout)
raise Exception('Unknown model cache engine `%s`' % engine)