From f99e45c7bb2ccccc86087091ddf1d7ec0c0f93d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Tue, 6 Sep 2022 07:54:44 +0000 Subject: [PATCH] SETTINGS.cache_size --- api/ovdashboard_api/dav_calendar.py | 4 ++-- api/ovdashboard_api/dav_common.py | 2 +- api/ovdashboard_api/dav_file.py | 2 +- api/ovdashboard_api/settings.py | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/api/ovdashboard_api/dav_calendar.py b/api/ovdashboard_api/dav_calendar.py index cbe46b2..d47c64c 100644 --- a/api/ovdashboard_api/dav_calendar.py +++ b/api/ovdashboard_api/dav_calendar.py @@ -94,7 +94,7 @@ class CalEvent(BaseModel): return cls.parse_obj(data) -@timed_alru_cache(maxsize=20) +@timed_alru_cache(maxsize=SETTINGS.cache_size) async def _get_calendar( calendar_name: str, ) -> Calendar: @@ -109,7 +109,7 @@ async def _get_calendar( return await _inner() -@timed_alru_cache(maxsize=20) +@timed_alru_cache(maxsize=SETTINGS.cache_size) async def _get_calendar_events( calendar_name: str, ) -> list[CalEvent]: diff --git a/api/ovdashboard_api/dav_common.py b/api/ovdashboard_api/dav_common.py index bcac62c..473ee19 100644 --- a/api/ovdashboard_api/dav_common.py +++ b/api/ovdashboard_api/dav_common.py @@ -20,7 +20,7 @@ _WEBDAV_CLIENT = WebDAVclient({ }) -@lru_cache +@lru_cache(maxsize=SETTINGS.cache_size) def webdav_resource(remote_path: Any) -> WebDAVResource: """ Gets a resource using the main WebDAV client. diff --git a/api/ovdashboard_api/dav_file.py b/api/ovdashboard_api/dav_file.py index 7fc1e11..c6a532b 100644 --- a/api/ovdashboard_api/dav_file.py +++ b/api/ovdashboard_api/dav_file.py @@ -18,7 +18,7 @@ from .settings import SETTINGS _logger = logging.getLogger(__name__) -@timed_alru_cache(maxsize=20) +@timed_alru_cache(maxsize=SETTINGS.cache_size) async def _get_buffer( remote_path: Any, ) -> BytesIO: diff --git a/api/ovdashboard_api/settings.py b/api/ovdashboard_api/settings.py index 3b07198..652b02d 100644 --- a/api/ovdashboard_api/settings.py +++ b/api/ovdashboard_api/settings.py @@ -58,6 +58,7 @@ class Settings(BaseSettings): caldav: DavSettings = DavSettings() cache_seconds: int = 30 + cache_size: int = 30 class Config: env_nested_delimiter = "__"