mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-07-08 00:01:27 +08:00
fix #4014
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import inspect
|
import inspect
|
||||||
import json
|
import json
|
||||||
import pickle
|
import pickle
|
||||||
|
import threading
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
@@ -16,6 +17,8 @@ from app.log import logger
|
|||||||
# 默认缓存区
|
# 默认缓存区
|
||||||
DEFAULT_CACHE_REGION = "DEFAULT"
|
DEFAULT_CACHE_REGION = "DEFAULT"
|
||||||
|
|
||||||
|
lock = threading.Lock()
|
||||||
|
|
||||||
|
|
||||||
class CacheBackend(ABC):
|
class CacheBackend(ABC):
|
||||||
"""
|
"""
|
||||||
@@ -163,7 +166,8 @@ class CacheToolsBackend(CacheBackend):
|
|||||||
# 如果该 key 尚未有缓存实例,则创建一个新的 TTLCache 实例
|
# 如果该 key 尚未有缓存实例,则创建一个新的 TTLCache 实例
|
||||||
region_cache = self._region_caches.setdefault(region, TTLCache(maxsize=maxsize, ttl=ttl))
|
region_cache = self._region_caches.setdefault(region, TTLCache(maxsize=maxsize, ttl=ttl))
|
||||||
# 设置缓存值
|
# 设置缓存值
|
||||||
region_cache[key] = value
|
with lock:
|
||||||
|
region_cache[key] = value
|
||||||
|
|
||||||
def exists(self, key: str, region: str = DEFAULT_CACHE_REGION) -> bool:
|
def exists(self, key: str, region: str = DEFAULT_CACHE_REGION) -> bool:
|
||||||
"""
|
"""
|
||||||
@@ -201,7 +205,8 @@ class CacheToolsBackend(CacheBackend):
|
|||||||
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 None
|
return None
|
||||||
del region_cache[key]
|
with lock:
|
||||||
|
del region_cache[key]
|
||||||
|
|
||||||
def clear(self, region: Optional[str] = None) -> None:
|
def clear(self, region: Optional[str] = None) -> None:
|
||||||
"""
|
"""
|
||||||
@@ -213,12 +218,14 @@ class CacheToolsBackend(CacheBackend):
|
|||||||
# 清理指定缓存区
|
# 清理指定缓存区
|
||||||
region_cache = self.__get_region_cache(region)
|
region_cache = self.__get_region_cache(region)
|
||||||
if region_cache:
|
if region_cache:
|
||||||
region_cache.clear()
|
with lock:
|
||||||
|
region_cache.clear()
|
||||||
logger.info(f"Cleared cache for region: {region}")
|
logger.info(f"Cleared cache for region: {region}")
|
||||||
else:
|
else:
|
||||||
# 清除所有区域的缓存
|
# 清除所有区域的缓存
|
||||||
for region_cache in self._region_caches.values():
|
for region_cache in self._region_caches.values():
|
||||||
region_cache.clear()
|
with lock:
|
||||||
|
region_cache.clear()
|
||||||
logger.info("Cleared all cache")
|
logger.info("Cleared all cache")
|
||||||
|
|
||||||
def close(self) -> None:
|
def close(self) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user