1
0
mirror of https://github.com/quay/quay.git synced 2026-01-26 06:21:37 +03:00
Files
quay/data/cache/__init__.py
Alec Merdler 1180ea99fa cache: remove GlobalLock from redis model cache (PROJQUAY-1902) (#755)
Remove GlobalLock from Redis model cache implementation in
favor of 'nx=True' when setting the key.

Signed-off-by: Alec Merdler <alecmerdler@gmail.com>
2021-04-19 19:06:18 -07:00

53 lines
1.6 KiB
Python

from data.cache.impl import (
NoopDataModelCache,
InMemoryDataModelCache,
MemcachedModelCache,
RedisDataModelCache,
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
if engine == "redis":
host = cache_config.get("host", None)
if host is None:
raise Exception("Missing `host` for Redis model cache configuration")
return RedisDataModelCache(
host=host,
port=cache_config.get("port", 6379),
password=cache_config.get("password", None),
db=cache_config.get("db", 0),
ca_cert=cache_config.get("ca_cert", None),
ssl=cache_config.get("ssl", False),
)
raise Exception("Unknown model cache engine `%s`" % engine)