Skip to content

Commit

Permalink
Limit cache entries to 10
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Jan 1, 2025
1 parent f5eb5de commit b8b2575
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions auto_editor/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,22 @@ def cache(self, arr: np.ndarray, kind: str, obj: Sequence[object]) -> np.ndarray
except Exception as e:
self.log.warning(f"Cache write failed: {e}")

cache_entries = []
with os.scandir(workdir) as entries:
for entry in entries:
if entry.name.endswith(".npz"):
cache_entries.append((entry.path, entry.stat().st_mtime))

if len(cache_entries) > 10:
# Sort by modification time, oldest first
cache_entries.sort(key=lambda x: x[1])
# Remove oldest files until we're back to 10
for filepath, _ in cache_entries[:-10]:
try:
os.remove(filepath)
except OSError:
pass

return arr

def audio(self, stream: int) -> NDArray[np.float32]:
Expand Down

0 comments on commit b8b2575

Please sign in to comment.