From ed555594488a1407e3b76bfb2d4d467d03afa1cd Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Wed, 30 Jun 2021 06:34:55 -0500 Subject: [PATCH] fix cache cleanup (fixes #1231) --- frigate/events.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/frigate/events.py b/frigate/events.py index 71e9990dcb..b8ff6cfd75 100644 --- a/frigate/events.py +++ b/frigate/events.py @@ -123,7 +123,7 @@ def refresh_cache(self): # if we are still using more than 90% of the cache, proactively cleanup cache_usage = shutil.disk_usage("/tmp/cache") - if ( + while ( cache_usage.used / cache_usage.total > 0.9 and cache_usage.free < 200000000 and len(self.cached_clips) > 0 @@ -133,13 +133,10 @@ def refresh_cache(self): "Consider increasing space available at /tmp/cache or reducing max_seconds in your clips config." ) logger.warning("Proactively cleaning up the cache...") - while cache_usage.used / cache_usage.total > 0.9: - oldest_clip = min( - self.cached_clips.values(), key=lambda x: x["start_time"] - ) - del self.cached_clips[oldest_clip["path"]] - os.remove(os.path.join(CACHE_DIR, oldest_clip["path"])) - cache_usage = shutil.disk_usage("/tmp/cache") + oldest_clip = min(self.cached_clips.values(), key=lambda x: x["start_time"]) + del self.cached_clips[oldest_clip["path"]] + os.remove(os.path.join(CACHE_DIR, oldest_clip["path"])) + cache_usage = shutil.disk_usage("/tmp/cache") def create_clip(self, camera, event_data, pre_capture, post_capture): # get all clips from the camera with the event sorted