rust-cached-path
rust-cached-path copied to clipboard
Add functionality to restrict the disk space used by the Cache
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
Hey @gbrls I'd be happy to review a PR for this. I see a couple paths forward:
- 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.
- 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.
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.
Perfect