diff --git a/app/chain/__init__.py b/app/chain/__init__.py index 5551d336..59a0bcbc 100644 --- a/app/chain/__init__.py +++ b/app/chain/__init__.py @@ -406,3 +406,9 @@ class ChainBase(metaclass=ABCMeta): 定时任务,每10分钟调用一次,模块实现该接口以实现定时服务 """ return self.run_module("scheduler_job") + + def clear_cache(self) -> None: + """ + 清理缓存,模块实现该接口响应清理缓存事件 + """ + return self.run_module("clear_cache") diff --git a/app/chain/system.py b/app/chain/system.py new file mode 100644 index 00000000..126ef865 --- /dev/null +++ b/app/chain/system.py @@ -0,0 +1,17 @@ +from typing import Union + +from app.chain import ChainBase +from app.schemas import Notification, MessageChannel + + +class SystemChain(ChainBase): + """ + 系统级处理链 + """ + def remote_clear_cache(self, channel: MessageChannel, userid: Union[int, str]): + """ + 清理系统缓存 + """ + self.clear_cache() + self.post_message(Notification(channel=channel, + title=f"缓存清理完成!", userid=userid)) diff --git a/app/command.py b/app/command.py index 95d45ed2..7f6652f5 100644 --- a/app/command.py +++ b/app/command.py @@ -8,6 +8,7 @@ from app.chain.download import DownloadChain from app.chain.mediaserver import MediaServerChain from app.chain.site import SiteChain from app.chain.subscribe import SubscribeChain +from app.chain.system import SystemChain from app.chain.transfer import TransferChain from app.core.event import Event as ManagerEvent from app.core.event import eventmanager, EventManager @@ -45,6 +46,8 @@ class Command(metaclass=Singleton): self.eventmanager = EventManager() # 插件管理器 self.pluginmanager = PluginManager() + # 处理链 + self.chain = CommandChian(self._db) # 内置命令 self._commands = { "/cookiecloud": { @@ -111,6 +114,11 @@ class Command(metaclass=Singleton): "func": TransferChain(self._db).remote_transfer, "description": "手动整理", "data": {} + }, + "/clear_cache": { + "func": SystemChain(self._db).remote_clear_cache, + "description": "清理缓存", + "data": {} } } # 汇总插件命令 @@ -125,8 +133,6 @@ class Command(metaclass=Singleton): 'data': command.get('data') } ) - # 处理链 - self.chain = CommandChian(self._db) # 广播注册命令菜单 self.chain.register_commands(commands=self.get_commands()) # 消息处理线程 diff --git a/app/modules/themoviedb/__init__.py b/app/modules/themoviedb/__init__.py index 42a64eec..a7170700 100644 --- a/app/modules/themoviedb/__init__.py +++ b/app/modules/themoviedb/__init__.py @@ -389,3 +389,10 @@ class TheMovieDbModule(_ModuleBase): :param page: 页码 """ return self.tmdb.get_person_credits(person_id=person_id, page=page) + + def clear_cache(self): + """ + 清除缓存 + """ + self.tmdb.clear_cache() + self.cache.clear() diff --git a/app/modules/themoviedb/tmdbapi.py b/app/modules/themoviedb/tmdbapi.py index 19066667..71d44a2e 100644 --- a/app/modules/themoviedb/tmdbapi.py +++ b/app/modules/themoviedb/tmdbapi.py @@ -1124,3 +1124,9 @@ class TmdbHelper: except Exception as e: print(str(e)) return [] + + def clear_cache(self): + """ + 清除缓存 + """ + self.tmdb.cache_clear()