diff options
| author | Nakidai <nakidai@disroot.org> | 2024-10-27 22:58:48 +0300 |
|---|---|---|
| committer | Nakidai <nakidai@disroot.org> | 2024-10-27 22:58:48 +0300 |
| commit | 4b2ddc03f1e35cb0dea51dc96a00fb0a0ca49031 (patch) | |
| tree | 815145638b46db57c1889940d7090272b3e89c2b | |
| parent | 6c0d85a696f5622a5959a49b6be4bb4c0a67393e (diff) | |
| download | petthecord-4b2ddc03f1e35cb0dea51dc96a00fb0a0ca49031.tar.gz petthecord-4b2ddc03f1e35cb0dea51dc96a00fb0a0ca49031.zip | |
Do gc in a loop
| -rw-r--r-- | src/petthecord/server.py | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/petthecord/server.py b/src/petthecord/server.py index 18ec2a2..28b49ee 100644 --- a/src/petthecord/server.py +++ b/src/petthecord/server.py @@ -107,19 +107,20 @@ class Server(Application): return Response(body=f.read(), content_type="image/gif") async def clean_cache(self) -> None: - if self.caching: - self._cache_logger.info("Starting new cache's gc iteration") - - for filename in listdir(self.cache_path): - path = (self.cache_path / filename) - if path.is_file() and filename != "index.json": - if (time() - getmtime(path) > self.cache_lifetime): - self._cache_logger.debug(f"Removing {filename}") - del self.cache[filename.split('_')[0]] - remove(path) - with open(self.cache_path / "index.json", "w") as f: - f.write(dumps(self.cache)) + while True: + if self.caching: + self._cache_logger.info("Starting new cache's gc iteration") + + for filename in listdir(self.cache_path): + path = (self.cache_path / filename) + if path.is_file() and filename != "index.json": + if (time() - getmtime(path) > self.cache_lifetime): + self._cache_logger.debug(f"Removing {filename}") + del self.cache[filename.split('_')[0]] + remove(path) + with open(self.cache_path / "index.json", "w") as f: + f.write(dumps(self.cache)) - self._cache_logger.debug("Finished collecting old cache") + self._cache_logger.debug("Finished collecting old cache") - await sleep(self.cache_gc_delay) + await sleep(self.cache_gc_delay) |