Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit cache entries to 10 #618

Merged
merged 1 commit into from
Jan 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading