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