diff --git a/app/chain/message.py b/app/chain/message.py index c0ac3645..827389a2 100644 --- a/app/chain/message.py +++ b/app/chain/message.py @@ -1,5 +1,5 @@ from typing import Any - +import gc from app.chain.download import * from app.chain.media import MediaChain from app.chain.search import SearchChain @@ -312,6 +312,9 @@ class MessageChain(ChainBase): userid=userid, total=len(medias)) # 保存缓存 self.save_cache(user_cache, self._cache_file) + # 主动回收内存 + del user_cache + gc.collect() def __post_medias_message(self, channel: MessageChannel, title: str, items: list, userid: str, total: int): diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index 6dc7543d..4d28ecc7 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -1,5 +1,6 @@ import json import re +import gc from datetime import datetime from typing import Dict, List, Optional, Union, Tuple @@ -415,6 +416,9 @@ class SubscribeChain(ChainBase): self.__match(torrents_cache) # 保存缓存到本地 self.save_cache(torrents_cache, self._cache_file) + # 主动回收内存 + del torrents_cache + gc.collect() def __match(self, torrents_cache: Dict[str, List[Context]]): """ diff --git a/app/modules/themoviedb/tmdbv3api/tmdb.py b/app/modules/themoviedb/tmdbv3api/tmdb.py index 21a3bd8d..a667dd2b 100644 --- a/app/modules/themoviedb/tmdbv3api/tmdb.py +++ b/app/modules/themoviedb/tmdbv3api/tmdb.py @@ -130,10 +130,9 @@ class TMDb(object): def cache(self, cache): os.environ[self.TMDB_CACHE_ENABLED] = str(cache) - @staticmethod @lru_cache(maxsize=REQUEST_CACHE_MAXSIZE) - def cached_request(method, url, data, json, proxies): - return requests.request(method, url, data=data, json=json, proxies=proxies) + def cached_request(self, method, url, data, json): + return requests.request(method, url, data=data, json=json, proxies=self.proxies) def cache_clear(self): return self.cached_request.cache_clear() @@ -151,7 +150,7 @@ class TMDb(object): ) if self.cache and self.obj_cached and call_cached and method != "POST": - req = self.cached_request(method, url, data, json, self.proxies) + req = self.cached_request(method, url, data, json) else: req = self.__class__._session.request(method, url, data=data, json=json, proxies=self.proxies)