Skip to content

Commit

Permalink
Rm old cache (#320)
Browse files Browse the repository at this point in the history
* remove old cache

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fastapi==0.108.0

* pathy=0.10.3

* pathy==0.10.3

* update requirements

* remove background tasks in cache

* role back requirements

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* more robust cache tidy up

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
peterdudfield and pre-commit-ci[bot] authored Jan 23, 2024
1 parent ff228fa commit 633e76e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,21 @@ def remove_old_cache(
now = datetime.now(tz=timezone.utc)
logger.info("Removing old cache entries")
keys_to_remove = []
for key, value in last_updated.items():
last_updated_copy = last_updated.copy()
for key, value in last_updated_copy.items():
if now - timedelta(seconds=remove_cache_time_seconds) > value:
logger.debug(f"Removing {key} from cache, ({value})")
keys_to_remove.append(key)

for key in keys_to_remove:
last_updated.pop(key)
response.pop(key)
try:
last_updated.pop(key)
response.pop(key)
except KeyError:
logger.warning(
f"Could not remove {key} from cache. "
f"This could be because it has already been removed"
)

return last_updated, response

Expand Down

0 comments on commit 633e76e

Please sign in to comment.