🔨 refactor(base.py): remove inheritance of Service class from BaseCacheManager to simplify class hierarchy

🔨 refactor(factory.py): add type hinting for settings_manager parameter in create method of CacheManagerFactory

🔨 refactor(manager.py): remove inheritance of Service class from InMemoryCache and RedisCache to simplify class hierarchy
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-09-01 17:21:40 -03:00
commit d508a1407c
3 changed files with 9 additions and 6 deletions

View file

@ -1,9 +1,7 @@
import abc
from langflow.services.base import Service
class BaseCacheManager(abc.ABC, Service):
class BaseCacheManager(abc.ABC):
"""
Abstract base class for a cache.
"""

View file

@ -1,13 +1,17 @@
from langflow.services.cache.manager import InMemoryCache, RedisCache, BaseCacheManager
from langflow.services.factory import ServiceFactory
from langflow.utils.logger import logger
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from langflow.services.settings.manager import SettingsManager
class CacheManagerFactory(ServiceFactory):
def __init__(self):
super().__init__(BaseCacheManager)
def create(self, settings_manager):
def create(self, settings_manager: "SettingsManager"):
# Here you would have logic to create and configure a CacheManager
# based on the settings_service

View file

@ -1,13 +1,14 @@
import threading
import time
from collections import OrderedDict
from langflow.services.base import Service
from langflow.services.cache.base import BaseCacheManager
import pickle
class InMemoryCache(BaseCacheManager):
class InMemoryCache(BaseCacheManager, Service):
"""
A simple in-memory cache using an OrderedDict.
@ -175,7 +176,7 @@ class InMemoryCache(BaseCacheManager):
return f"InMemoryCache(max_size={self.max_size}, expiration_time={self.expiration_time})"
class RedisCache(BaseCacheManager):
class RedisCache(BaseCacheManager, Service):
"""
A Redis-based cache implementation.