hack: invalidate cache on file write

This commit is contained in:
Jörn-Michael Miehe 2023-09-11 02:59:11 +00:00
parent 5c583bd478
commit 4415c0f861

View file

@ -2,6 +2,7 @@ import re
from io import BytesIO
from cache import AsyncTTL
from cache.key import KEY
from webdav3.client import Client as WebDAVclient
from .settings import SETTINGS
@ -42,7 +43,7 @@ class WebDAV:
return cls._webdav_client.check(path)
@classmethod
@AsyncTTL(time_to_live=SETTINGS.webdav.cache_ttl, skip_args=1)
@(_rb_ttl := AsyncTTL(time_to_live=SETTINGS.webdav.cache_ttl, skip_args=1))
async def read_bytes(cls, path: str) -> bytes:
"""
Datei aus Pfad `path` als bytes laden
@ -70,6 +71,9 @@ class WebDAV:
cls._webdav_client.resource(path).read_from(buffer)
# Cache-Eintrag entfernen (hack: siehe AsyncTTL._TTL.__contains__)
del cls._rb_ttl.ttl[KEY((path,), {})]
@classmethod
async def write_str(cls, path: str, content: str, encoding="utf-8") -> None:
"""