From 0f1df03b9e410d03d2ce681ff69fa7746413db5d Mon Sep 17 00:00:00 2001 From: tianxiu2b2t Date: Thu, 2 May 2024 09:57:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E6=BB=9A=E4=B8=80=E4=BA=9B=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/cluster.py | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/core/cluster.py b/core/cluster.py index 92de5b7..0926562 100644 --- a/core/cluster.py +++ b/core/cluster.py @@ -521,7 +521,7 @@ def __init__(self, name: str, dir: Path, width: int) -> None: if self.dir.is_file(): raise FileExistsError(f"Cannot copy file: '{self.dir}': Is a file.") self.dir.mkdir(exist_ok=True, parents=True) - self.cache: CacheManager = CacheManager(FileType.LOCAL, FileContentType.DATA if CACHE_ENABLE else FileContentType.PATH) + self.cache: dict[str, File] = {} self.timer = scheduler.repeat( self.clear_cache, delay=CHECK_CACHE, interval=CHECK_CACHE ) @@ -902,7 +902,7 @@ async def write(self, hash: str, io: io.BytesIO) -> int: path = self._file_endpoint(f"{hash[:2]}/{hash}") await self._mkdir(self._file_endpoint(f"{hash[:2]}")) await self._execute(self.session.upload_to(io.getbuffer(), path)) - self.files[hash] = File(path, hash, len(io.getbuffer())) + self.files[hash] = File(path, hash, len(io.getbuffer()), FileContentType.URL) return self.files[hash].size async def get_files(self, dir: str) -> list[str]: @@ -1341,27 +1341,10 @@ async def message(self, channel, data: list[Any], callback=None): logger.error(traceback.format_exc()) -class CacheManager: - def __init__(self, type: FileType, data: FileContentType): - self.type = type - self.data = data - self.cache: dict[str, File] = {} - - def set(self, key: str, value: File) -> File: - self.cache[key] = value - return value - - def get_or_default(self, key: str) -> Optional[File]: - if key not in self.cache: - return None - return self.cache[key] - - token = TokenManager() cluster: Optional[Cluster] = None last_status: str = "-" storages = StorageManager() -cache: CacheManager = CacheManager() async def init(): if CLUSTER_ID == "":