Skip to content

Commit

Permalink
fix: add helper to easily remove files from the cache
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Nov 5, 2021
1 parent c6045a6 commit 9f6dca0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions beet/core/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ def has_changed(self, *filenames: Optional[FileSystemPath]) -> bool:

return changed

def discard(self, *filenames: Optional[FileSystemPath]):
"""Remove the given files from the cache and forget their last modification time."""
mtime = self.index.setdefault("mtime", {})

for filename in filenames:
if not filename:
continue

path = Path(filename)
key = str(path)

path.unlink(missing_ok=True)
mtime.pop(key, None)

@property
def expire(self) -> Optional[datetime]:
expire = self.index["expire"]
Expand Down

0 comments on commit 9f6dca0

Please sign in to comment.