modify: 排他锁

This commit is contained in:
2026-08-27 09:42:21 +08:00
parent 9f7f71be7c
commit 0bdee195c1
7 changed files with 159 additions and 2 deletions
+4
View File
@@ -47,6 +47,10 @@ class DiskBackend(CacheBackend):
def set(self, key, value, expire: float | None = None) -> None:
self._cache.set(key, value, expire=expire)
def set_nx(self, key, value, expire: float | None = None) -> bool:
# diskcache.add 仅在 key 不存在时写入,返回是否成功(SET NX 语义)且进程安全
return bool(self._cache.add(key, value, expire=expire))
def touch(self, key, expire: float | None = None) -> bool:
return self._cache.touch(key, expire=expire)