Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: inmemory and async cache expire configurable #2496

Merged
merged 5 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/backend/base/langflow/services/cache/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ def create(self, settings_service: "SettingsService"):
if redis_cache.is_connected():
logger.debug("Redis cache is connected")
return redis_cache
logger.warning("Redis cache is not connected, falling back to in-memory cache")
return AsyncInMemoryCache()
else:
# do not attempt to fallback to another cache type
raise ConnectionError("Failed to connect to Redis cache")

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":
return AsyncInMemoryCache()
return AsyncInMemoryCache(expiration_time=settings_service.settings.cache_expire)
2 changes: 2 additions & 0 deletions src/backend/base/langflow/services/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
cache_type: str = "async"
"""The cache type can be 'async' or 'redis'."""
cache_expire: int = 3600
"""The cache expire in seconds."""
variable_store: str = "db"
"""The store can be 'db' or 'kubernetes'."""

Expand Down