diff --git a/plugins/markov.py b/plugins/markov.py index 3a71d4c..a70ccea 100644 --- a/plugins/markov.py +++ b/plugins/markov.py @@ -44,11 +44,15 @@ class Chain: self.__last_access = 0.0 self.__dirty = False + def __touch(self): + self.__last_access = asyncio.get_running_loop().time() + @property def last_access(self) -> float: return self.__last_access def add(self, text: str): + self.__touch() parts: List[Any] = text.strip().split() if not parts: return @@ -60,7 +64,7 @@ class Chain: self.__dirty = True def get(self, key: str) -> dict[str | None, int]: - self.__last_access = asyncio.get_running_loop().time() + self.__touch() if self.__cache: if key in self.__cache: return self.__cache[key] @@ -72,7 +76,7 @@ class Chain: return self.__cache[key] def set(self, key: str, value: Mapping[str | None, int]): - self.__last_access = asyncio.get_running_loop().time() + self.__touch() if not self.__cache: # Attempt the cache before writing to it self.__load() @@ -80,7 +84,7 @@ class Chain: self.__dirty = True def __load(self): - self.__last_access = asyncio.get_running_loop().time() + self.__touch() if self.__cache: return if not self.path.exists():