From c6c84fe65b469e8f5c462e998efd09527007bd83 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Thu, 21 Aug 2025 16:02:50 +0800 Subject: [PATCH] rename --- app/api/endpoints/system.py | 6 +++--- app/chain/__init__.py | 6 +++--- app/chain/download.py | 4 ++-- app/chain/recommend.py | 6 +++--- app/core/cache.py | 10 +++++----- app/helper/torrent.py | 4 ++-- app/modules/douban/douban_cache.py | 4 ++-- app/modules/qbittorrent/__init__.py | 10 +++++----- app/modules/themoviedb/tmdb_cache.py | 4 ++-- app/modules/transmission/__init__.py | 8 ++++---- 10 files changed, 31 insertions(+), 31 deletions(-) diff --git a/app/api/endpoints/system.py b/app/api/endpoints/system.py index 6a830afa..eae507b7 100644 --- a/app/api/endpoints/system.py +++ b/app/api/endpoints/system.py @@ -17,7 +17,7 @@ from fastapi.responses import StreamingResponse from app import schemas from app.chain.search import SearchChain from app.chain.system import SystemChain -from app.core.cache import get_async_file_cache_backend +from app.core.cache import AsyncFileCache from app.core.config import global_vars, settings from app.core.event import eventmanager from app.core.metainfo import MetaInfo @@ -74,8 +74,8 @@ async def fetch_image( cache_path = cache_path.with_suffix(".jpg") # 缓存对像,缓存过期时间为全局图片缓存天数 - cache_backend = get_async_file_cache_backend(base=settings.CACHE_PATH, - ttl=settings.GLOBAL_IMAGE_CACHE_DAYS * 24 * 3600) + cache_backend = AsyncFileCache(base=settings.CACHE_PATH, + ttl=settings.GLOBAL_IMAGE_CACHE_DAYS * 24 * 3600) if use_cache: content = await cache_backend.get(cache_path.as_posix(), region="images") diff --git a/app/chain/__init__.py b/app/chain/__init__.py index 56a62e4a..1f20f929 100644 --- a/app/chain/__init__.py +++ b/app/chain/__init__.py @@ -11,7 +11,7 @@ from fastapi.concurrency import run_in_threadpool from qbittorrentapi import TorrentFilesList from transmission_rpc import File -from app.core.cache import get_file_cache_backend, get_async_file_cache_backend +from app.core.cache import FileCache, AsyncFileCache from app.core.config import settings from app.core.context import Context, MediaInfo, TorrentInfo from app.core.event import EventManager @@ -46,8 +46,8 @@ class ChainBase(metaclass=ABCMeta): send_callback=self.run_module ) self.pluginmanager = PluginManager() - self.filecache = get_file_cache_backend() - self.async_filecache = get_async_file_cache_backend() + self.filecache = FileCache() + self.async_filecache = AsyncFileCache() def load_cache(self, filename: str) -> Any: """ diff --git a/app/chain/download.py b/app/chain/download.py index 0c88da42..13b8eafe 100644 --- a/app/chain/download.py +++ b/app/chain/download.py @@ -8,7 +8,7 @@ from typing import List, Optional, Tuple, Set, Dict, Union from app import schemas from app.chain import ChainBase -from app.core.cache import get_file_cache_backend +from app.core.cache import FileCache from app.core.config import settings, global_vars from app.core.context import MediaInfo, TorrentInfo, Context from app.core.event import eventmanager, Event @@ -222,7 +222,7 @@ class DownloadChain(ChainBase): torrent_content = torrent_file.read_bytes() else: # 缓存处理器 - cache_backend = get_file_cache_backend() + cache_backend = FileCache() # 读取缓存的种子文件 torrent_content = cache_backend.get(torrent_file.as_posix(), region="torrents") diff --git a/app/chain/recommend.py b/app/chain/recommend.py index 83391c03..9dba6f65 100644 --- a/app/chain/recommend.py +++ b/app/chain/recommend.py @@ -9,7 +9,7 @@ from app.chain import ChainBase from app.chain.bangumi import BangumiChain from app.chain.douban import DoubanChain from app.chain.tmdb import TmdbChain -from app.core.cache import cached, get_file_cache_backend +from app.core.cache import cached, FileCache from app.core.config import settings, global_vars from app.log import logger from app.schemas import MediaType @@ -111,8 +111,8 @@ class RecommendChain(ChainBase, metaclass=Singleton): cache_path = cache_path.with_suffix(".jpg") # 获取缓存后端,并设置缓存时间为全局配置的缓存天数 - cache_backend = get_file_cache_backend(base=settings.CACHE_PATH, - ttl=settings.GLOBAL_IMAGE_CACHE_DAYS * 24 * 3600) + cache_backend = FileCache(base=settings.CACHE_PATH, + ttl=settings.GLOBAL_IMAGE_CACHE_DAYS * 24 * 3600) # 本地存在缓存图片,则直接跳过 if cache_backend.get(cache_path.as_posix(), region="images"): diff --git a/app/core/cache.py b/app/core/cache.py index 594dd3b4..5c34d830 100644 --- a/app/core/cache.py +++ b/app/core/cache.py @@ -762,7 +762,7 @@ class AsyncFileBackend(AsyncCacheBackend): pass -def get_file_cache_backend(base: Path = settings.TEMP_PATH, ttl: Optional[int] = None) -> CacheBackend: +def FileCache(base: Path = settings.TEMP_PATH, ttl: Optional[int] = None) -> CacheBackend: """ 获取文件缓存后端实例(Redis或文件系统) """ @@ -774,7 +774,7 @@ def get_file_cache_backend(base: Path = settings.TEMP_PATH, ttl: Optional[int] = return FileBackend(base=base) -def get_async_file_cache_backend(base: Path = settings.TEMP_PATH, ttl: Optional[int] = None) -> AsyncCacheBackend: +def AsyncFileCache(base: Path = settings.TEMP_PATH, ttl: Optional[int] = None) -> AsyncCacheBackend: """ 获取文件异步缓存后端实例(Redis或文件系统) """ @@ -786,7 +786,7 @@ def get_async_file_cache_backend(base: Path = settings.TEMP_PATH, ttl: Optional[ return AsyncFileBackend(base=base) -def get_cache_backend(maxsize: Optional[int] = 512, ttl: Optional[int] = 1800) -> CacheBackend: +def Cache(maxsize: Optional[int] = 512, ttl: Optional[int] = 1800) -> CacheBackend: """ 根据配置获取缓存后端实例(内存或Redis) @@ -822,7 +822,7 @@ class TTLCache: self.region = region self.maxsize = maxsize self.ttl = ttl - self._backend = get_cache_backend(maxsize=maxsize, ttl=ttl) + self._backend = Cache(maxsize=maxsize, ttl=ttl) def __getitem__(self, key: str): """ @@ -927,7 +927,7 @@ def cached(region: Optional[str] = None, maxsize: Optional[int] = 512, ttl: Opti :return: 装饰器函数 """ # 缓存后端实例 - cache_backend = get_cache_backend(maxsize=maxsize, ttl=ttl) + cache_backend = Cache(maxsize=maxsize, ttl=ttl) def should_cache(value: Any) -> bool: """ diff --git a/app/helper/torrent.py b/app/helper/torrent.py index 6c3264ee..f501c63b 100644 --- a/app/helper/torrent.py +++ b/app/helper/torrent.py @@ -6,7 +6,7 @@ from urllib.parse import unquote from torrentool.api import Torrent -from app.core.cache import get_file_cache_backend +from app.core.cache import FileCache from app.core.config import settings from app.core.context import Context, TorrentInfo, MediaInfo from app.core.meta import MetaBase @@ -43,7 +43,7 @@ class TorrentHelper(metaclass=WeakSingleton): # 构建 torrent 种子文件的缓存路径 cache_path = Path(StringUtils.md5_hash(url)).with_suffix(".torrent") # 缓存处理器 - cache_backend = get_file_cache_backend() + cache_backend = FileCache() # 读取缓存的种子文件 torrent_content = cache_backend.get(cache_path.as_posix(), region="torrents") if torrent_content: diff --git a/app/modules/douban/douban_cache.py b/app/modules/douban/douban_cache.py index 6fa3b777..e5cbe259 100644 --- a/app/modules/douban/douban_cache.py +++ b/app/modules/douban/douban_cache.py @@ -4,7 +4,7 @@ from pathlib import Path from threading import RLock from typing import Optional -from app.core.cache import get_cache_backend +from app.core.cache import Cache from app.core.config import settings from app.core.meta import MetaBase from app.core.metainfo import MetaInfo @@ -34,7 +34,7 @@ class DoubanCache(metaclass=WeakSingleton): self.region = "__douban_cache__" self._meta_filepath = settings.TEMP_PATH / self.region # 初始化缓存 - self._cache = get_cache_backend(maxsize=self.maxsize, ttl=self.ttl) + self._cache = Cache(maxsize=self.maxsize, ttl=self.ttl) # 非Redis加载本地缓存数据 if not self._cache.is_redis(): for key, value in self.__load(self._meta_filepath).items(): diff --git a/app/modules/qbittorrent/__init__.py b/app/modules/qbittorrent/__init__.py index 6d5f5f78..0d872505 100644 --- a/app/modules/qbittorrent/__init__.py +++ b/app/modules/qbittorrent/__init__.py @@ -5,10 +5,10 @@ from qbittorrentapi import TorrentFilesList from torrentool.torrent import Torrent from app import schemas -from app.core.cache import get_file_cache_backend +from app.core.cache import FileCache from app.core.config import settings -from app.core.metainfo import MetaInfo from app.core.event import eventmanager, Event +from app.core.metainfo import MetaInfo from app.log import logger from app.modules import _ModuleBase, _DownloaderBase from app.modules.qbittorrent.qbittorrent import Qbittorrent @@ -119,7 +119,7 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]): torrent_content = content.read_bytes() else: # 缓存处理器 - cache_backend = get_file_cache_backend() + cache_backend = FileCache() # 读取缓存的种子文件 torrent_content = cache_backend.get(content.as_posix(), region="torrents") else: @@ -137,7 +137,7 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]): return None, None, None, "下载内容为空" # 读取种子的名称 - torrent, content = __get_torrent_info() + torrent, content = __get_torrent_info() if not torrent: return None, None, None, f"添加种子任务失败:无法读取种子文件" @@ -337,7 +337,7 @@ class QbittorrentModule(_ModuleBase, _DownloaderBase[Qbittorrent]): del torrents else: return None - return ret_torrents # noqa + return ret_torrents # noqa def transfer_completed(self, hashs: str, downloader: Optional[str] = None) -> None: """ diff --git a/app/modules/themoviedb/tmdb_cache.py b/app/modules/themoviedb/tmdb_cache.py index b0ceaca8..91fd0289 100644 --- a/app/modules/themoviedb/tmdb_cache.py +++ b/app/modules/themoviedb/tmdb_cache.py @@ -3,7 +3,7 @@ import traceback from pathlib import Path from threading import RLock -from app.core.cache import get_cache_backend +from app.core.cache import Cache from app.core.config import settings from app.core.meta import MetaBase from app.log import logger @@ -32,7 +32,7 @@ class TmdbCache(metaclass=WeakSingleton): self.region = "__tmdb_cache__" self._meta_filepath = settings.TEMP_PATH / self.region # 初始化缓存 - self._cache = get_cache_backend(maxsize=self.maxsize, ttl=self.ttl) + self._cache = Cache(maxsize=self.maxsize, ttl=self.ttl) # 非Redis加载本地缓存数据 if not self._cache.is_redis(): for key, value in self.__load(self._meta_filepath).items(): diff --git a/app/modules/transmission/__init__.py b/app/modules/transmission/__init__.py index 3c36e1f7..6c2d3e84 100644 --- a/app/modules/transmission/__init__.py +++ b/app/modules/transmission/__init__.py @@ -5,10 +5,10 @@ from torrentool.torrent import Torrent from transmission_rpc import File from app import schemas -from app.core.cache import get_file_cache_backend +from app.core.cache import FileCache from app.core.config import settings -from app.core.metainfo import MetaInfo from app.core.event import eventmanager, Event +from app.core.metainfo import MetaInfo from app.log import logger from app.modules import _ModuleBase, _DownloaderBase from app.modules.transmission.transmission import Transmission @@ -120,7 +120,7 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]): torrent_content = content.read_bytes() else: # 缓存处理器 - cache_backend = get_file_cache_backend() + cache_backend = FileCache() # 读取缓存的种子文件 torrent_content = cache_backend.get(content.as_posix(), region="torrents") else: @@ -325,7 +325,7 @@ class TransmissionModule(_ModuleBase, _DownloaderBase[Transmission]): del torrents else: return None - return ret_torrents # noqa + return ret_torrents # noqa def transfer_completed(self, hashs: str, downloader: Optional[str] = None) -> None: """