fix 优化远程交互内存占用

This commit is contained in:
jxxghp
2023-07-22 08:35:52 +08:00
parent fbcd5f05c0
commit ce05b25f87
3 changed files with 33 additions and 28 deletions
+19
View File
@@ -1,9 +1,11 @@
import pickle
import traceback
from pathlib import Path
from typing import Optional, Any, Tuple, List, Set, Union, Dict
from ruamel.yaml import CommentedMap
from app.core.config import settings
from app.core.context import Context
from app.core.context import MediaInfo, TorrentInfo
from app.core.event import EventManager
@@ -28,6 +30,23 @@ class ChainBase(AbstractSingleton, metaclass=Singleton):
self.modulemanager = ModuleManager()
self.eventmanager = EventManager()
@staticmethod
def __load_cache(filename: str) -> Any:
"""
从本地加载缓存
"""
cache_path = settings.TEMP_PATH / filename
if cache_path.exists():
return pickle.load(cache_path.open('rb'))
return None
@staticmethod
def __save_cache(cache: Any, filename: str) -> None:
"""
保存缓存到本地
"""
pickle.dump(cache, (settings.TEMP_PATH / filename).open('wb'))
def run_module(self, method: str, *args, **kwargs) -> Any:
"""
运行包含该方法的所有模块,然后返回结果