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
Kenny Lee Sin Cheong 5f63b3a7bb chore: drop deprecated tables and remove unused code (PROJQUAY-522) (#2089)
* chore: drop deprecated tables and remove unused code

* isort imports

* migration: check for table existence before drop
2023-08-25 12:17:24 -04:00

47 lines
1.4 KiB
Python

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