diff --git a/persistence/memory.py b/persistence/memory.py index 19d32c49..2e3ba72a 100644 --- a/persistence/memory.py +++ b/persistence/memory.py @@ -49,7 +49,8 @@ async def aget(self, key: str) -> bytes | None: res = self._cache.get(sha_key, None) if not res: return None - self._cache.move_to_end(sha_key, last=False) # Move to first + # Move to first + self._cache.move_to_end(sha_key, last=False) return res async def aset(self, key: str, value: str | bytes | None, ttl_sec: int) -> bool: @@ -57,8 +58,9 @@ async def aset(self, key: str, value: str | bytes | None, ttl_sec: int) -> bool: Set a value in the cache. """ sha_key = self._key_to_hash(key) + # Delete the last if full if len(self._cache) >= self._config.max_size: - self._cache.popitem() # Delete the last + self._cache.popitem() # Add to first self._cache[sha_key] = value.encode() if isinstance(value, str) else value self._cache.move_to_end(sha_key, last=False) diff --git a/tests/conftest.py b/tests/conftest.py index b26093dc..1d1b6bd7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -165,6 +165,7 @@ def generate(self, prompt: str) -> tuple[str, float]: res = super().generate(prompt) # Update cache self._cache.set(cache_key, res) + # Return return res async def a_generate(self, prompt: str) -> tuple[str, float]: @@ -178,6 +179,7 @@ async def a_generate(self, prompt: str) -> tuple[str, float]: res = await super().a_generate(prompt) # Update cache self._cache.set(cache_key, res) + # Return return res def get_model_name(self) -> str: