diff --git a/core/config.py b/core/config.py index 83a941a..14f06f5 100644 --- a/core/config.py +++ b/core/config.py @@ -150,6 +150,12 @@ class DatabaseConfig: default=10000, ) + @property + def enable_memcached(self) -> bool: + return CoreConfig.get_config_field( + self.__config, "core", "database", "enable_memcached", default=True + ) + @property def memcached_host(self) -> str: return CoreConfig.get_config_field( diff --git a/core/data/cache.py b/core/data/cache.py index cabf597..1490826 100644 --- a/core/data/cache.py +++ b/core/data/cache.py @@ -17,7 +17,7 @@ except ModuleNotFoundError: def cached(lifetime: int = 10, extra_key: Any = None) -> Callable: def _cached(func: Callable) -> Callable: - if has_mc: + if has_mc and (cfg and cfg.database.enable_memcached): hostname = "127.0.0.1" if cfg: hostname = cfg.database.memcached_host diff --git a/example_config/core.yaml b/example_config/core.yaml index 1ecb7ff..76ec5b1 100644 --- a/example_config/core.yaml +++ b/example_config/core.yaml @@ -24,6 +24,7 @@ database: sha2_password: False loglevel: "warn" user_table_autoincrement_start: 10000 + enable_memcached: True memcached_host: "localhost" frontend: