1
0
mirror of https://github.com/quay/quay.git synced 2026-01-27 18:42:52 +03:00
Files
quay/data/cache/__init__.py
Joseph Schorr 9a9608de3f Adds a pre-disconnect option to memcache (#459)
Add a config option for configuring whether to pre-disconnect from the
DB before making a memcache call
2020-06-25 16:08:36 -04:00

38 lines
1.1 KiB
Python

from data.cache.impl import (
NoopDataModelCache,
InMemoryDataModelCache,
MemcachedModelCache,
DisconnectWrapper,
)
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")
predisconnect = cache_config.get("predisconnect_from_db")
cache = MemcachedModelCache(endpoint, timeout=timeout, connect_timeout=connect_timeout)
if predisconnect:
cache = DisconnectWrapper(cache, config)
return cache
raise Exception("Unknown model cache engine `%s`" % engine)