Skip to content

Commit b8b2575

Browse files
committed
Limit cache entries to 10
1 parent f5eb5de commit b8b2575

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

auto_editor/analyze.py

+16
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,22 @@ def cache(self, arr: np.ndarray, kind: str, obj: Sequence[object]) -> np.ndarray
235235
except Exception as e:
236236
self.log.warning(f"Cache write failed: {e}")
237237

238+
cache_entries = []
239+
with os.scandir(workdir) as entries:
240+
for entry in entries:
241+
if entry.name.endswith(".npz"):
242+
cache_entries.append((entry.path, entry.stat().st_mtime))
243+
244+
if len(cache_entries) > 10:
245+
# Sort by modification time, oldest first
246+
cache_entries.sort(key=lambda x: x[1])
247+
# Remove oldest files until we're back to 10
248+
for filepath, _ in cache_entries[:-10]:
249+
try:
250+
os.remove(filepath)
251+
except OSError:
252+
pass
253+
238254
return arr
239255

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

0 commit comments

Comments
 (0)