rust-cached-path icon indicating copy to clipboard operation
rust-cached-path copied to clipboard

Add functionality to restrict the disk space used by the Cache

Open gbrls opened this issue 2 years ago • 3 comments

Hello @epwalsh, thank you for this project, it's very useful! One issue that I have is that the cache sometimes takes up all of the disk space, for when I'm doing an operation that moved a lot of data around. A solution for that would be to implement a maximum size which the cache can occupy on disk and a strategy to remove entries.

If you have some specific idea or direction on how this could be implemented I'd be happy to do it and write tests for it. Cheers

gbrls avatar Oct 24 '23 13:10 gbrls

Hey @gbrls I'd be happy to review a PR for this. I see a couple paths forward:

  1. Add a function that needs to be called manually by the end users. It could take several options that determine which artifacts are removed, like a glob on resource names (URLs), a size cutoff, etc.
  2. Add a setting that does removal automatically every time cached_path() is called.

These are not necessarily mutually exclusive, and maybe (1) is just a good first step to (2) anyway.

As far as cache removal options, I think it would make sense to have an LRU option, i.e. remove resources that were accessed less recently first. For that we could keep track of last_accessed time in the resource metadata here.

epwalsh avatar Oct 25 '23 18:10 epwalsh

Cool! I'll first send a PR to delete the compressed archive after it has been extracted, that'd already help with the storage issue.

gbrls avatar Oct 25 '23 22:10 gbrls

Perfect

epwalsh avatar Oct 25 '23 22:10 epwalsh