diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a7d649..8ae98be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Changelog All notable changes to this project will be documented in this file. +## [0.2.2] +### Fixed +- Fix local cache set existing key, policy should not update + +### Changed +- Bump Cacheme-utils version + ## [0.2.1] ### Added - Remove expired nodes automatically diff --git a/cacheme/storages/local.py b/cacheme/storages/local.py index 80ae1ec..a3ddd43 100644 --- a/cacheme/storages/local.py +++ b/cacheme/storages/local.py @@ -47,6 +47,7 @@ async def set_by_key( value: Any, ttl: Optional[timedelta], ): + exist = key in self.cache expire = None if ttl is not None: expire = datetime.now(timezone.utc) + ttl @@ -54,6 +55,8 @@ async def set_by_key( data=value, updated_at=datetime.now(timezone.utc), expire=expire ) self.cache.move_to_end(key) + if exist: + return evicated = self.policy.set(key) if evicated is not None: self.cache.pop(evicated, None) diff --git a/pyproject.toml b/pyproject.toml index 1638b57..c94c15e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cacheme" -version = "0.2.1" +version = "0.2.2" description = "async caching framework" authors = ["Yiling-J "] readme = "README.md"