feat: inmemory and async cache expire configurable (#2496)
inmemory and async cache expire configurable
This commit is contained in:
parent
7abf697b7b
commit
f6636551bb
2 changed files with 7 additions and 4 deletions
|
|
@ -28,10 +28,11 @@ class CacheServiceFactory(ServiceFactory):
|
||||||
if redis_cache.is_connected():
|
if redis_cache.is_connected():
|
||||||
logger.debug("Redis cache is connected")
|
logger.debug("Redis cache is connected")
|
||||||
return redis_cache
|
return redis_cache
|
||||||
logger.warning("Redis cache is not connected, falling back to in-memory cache")
|
else:
|
||||||
return AsyncInMemoryCache()
|
# do not attempt to fallback to another cache type
|
||||||
|
raise ConnectionError("Failed to connect to Redis cache")
|
||||||
|
|
||||||
elif settings_service.settings.cache_type == "memory":
|
elif settings_service.settings.cache_type == "memory":
|
||||||
return ThreadingInMemoryCache()
|
return ThreadingInMemoryCache(expiration_time=settings_service.settings.cache_expire)
|
||||||
elif settings_service.settings.cache_type == "async":
|
elif settings_service.settings.cache_type == "async":
|
||||||
return AsyncInMemoryCache()
|
return AsyncInMemoryCache(expiration_time=settings_service.settings.cache_expire)
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,8 @@ class Settings(BaseSettings):
|
||||||
"""The number of connections to allow that can be opened beyond the pool size. If not provided, the default is 10."""
|
"""The number of connections to allow that can be opened beyond the pool size. If not provided, the default is 10."""
|
||||||
cache_type: str = "async"
|
cache_type: str = "async"
|
||||||
"""The cache type can be 'async' or 'redis'."""
|
"""The cache type can be 'async' or 'redis'."""
|
||||||
|
cache_expire: int = 3600
|
||||||
|
"""The cache expire in seconds."""
|
||||||
variable_store: str = "db"
|
variable_store: str = "db"
|
||||||
"""The store can be 'db' or 'kubernetes'."""
|
"""The store can be 'db' or 'kubernetes'."""
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue