mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-04-05 11:47:50 +08:00
修复缓存迭代时的并发问题
This commit is contained in:
@@ -474,7 +474,11 @@ class MemoryBackend(CacheBackend):
|
||||
if region_cache is None:
|
||||
yield from ()
|
||||
return
|
||||
for item in region_cache.items():
|
||||
# 使用锁保护迭代过程,避免在迭代时缓存被修改
|
||||
with lock:
|
||||
# 创建快照避免并发修改问题
|
||||
items_snapshot = list(region_cache.items())
|
||||
for item in items_snapshot:
|
||||
yield item
|
||||
|
||||
def close(self) -> None:
|
||||
@@ -603,7 +607,11 @@ class AsyncMemoryBackend(AsyncCacheBackend):
|
||||
region_cache = self.__get_region_cache(region)
|
||||
if region_cache is None:
|
||||
return
|
||||
for item in region_cache.items():
|
||||
# 使用锁保护迭代过程,避免在迭代时缓存被修改
|
||||
with lock:
|
||||
# 创建快照避免并发修改问题
|
||||
items_snapshot = list(region_cache.items())
|
||||
for item in items_snapshot:
|
||||
yield item
|
||||
|
||||
async def close(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user