Skip to content

Commit

Permalink
add notes
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Apr 19, 2024
1 parent ea82013 commit c9aa6c6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion boa/util/disk_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@


@contextlib.contextmanager
# silence errors which can be thrown when handling a file that does
# not exist
def _silence_io_errors():
try:
yield
Expand All @@ -30,12 +32,16 @@ def gc(self, force=False):
for root, dirs, files in os.walk(self.cache_dir):
# delete items older than ttl
for f in files:
# squash errors, file might have been removed in race
# (both p.stat() and p.unlink() can throw)
with _silence_io_errors():
p = Path(root).joinpath(Path(f))
if time.time() - p.stat().st_atime > self.ttl or force:
p.unlink()

# prune empty directories
for d in dirs:
# prune empty directories
# squash errors, directory might have been removed in race
with _silence_io_errors():
Path(root).joinpath(Path(d)).rmdir()

Expand Down

0 comments on commit c9aa6c6

Please sign in to comment.