Skip to content

Commit

Permalink
Background cache pruner
Browse files Browse the repository at this point in the history
  • Loading branch information
nsmith- committed Mar 6, 2024
1 parent 092267b commit 4551898
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/fsspec_xrootd/xrootd.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,12 @@ def _vectors_to_chunks(


class ReadonlyFileHandleCache:

Check warning on line 145 in src/fsspec_xrootd/xrootd.py

View workflow job for this annotation

GitHub Actions / Format

Missing class docstring
def __init__(self, loop: Any, max_items: int | None, ttl: int | None):
def __init__(self, loop: Any, max_items: int | None, ttl: int):
self.loop = loop
self._max_items = max_items
self._ttl = ttl
self._ttl = int(ttl)
self._cache: dict[str, dict[str, Any]] = {}
sync(loop, self._start_pruner)
weakref.finalize(self, self._close_all, loop, self._cache)

@staticmethod
Expand Down Expand Up @@ -181,6 +182,14 @@ async def _close(self, url: str, timeout: int) -> None:

close = sync_wrapper(_close)

async def _start_pruner(self) -> None:
self._prune_task = asyncio.create_task(self._pruner())

Check warning on line 186 in src/fsspec_xrootd/xrootd.py

View workflow job for this annotation

GitHub Actions / Format

Attribute '_prune_task' defined outside __init__

async def _pruner(self) -> None:
while True:
await self._prune_cache(self._ttl // 2)
await asyncio.sleep(self._ttl)

async def _prune_cache(self, timeout: int) -> None:
now = time.monotonic()
oldest_keys = sorted(
Expand Down

0 comments on commit 4551898

Please sign in to comment.