npm / cacache

npm's content-addressable cache
Other
280 stars 31 forks source link

[FEATURE] implement reference counting #52

Open nlf opened 3 years ago

nlf commented 3 years ago

What / Why

In order to safely prune old content after storing fresh content in the cache, we need some means of knowing if the old content has now become orphaned. The fastest approach to this is reference counting.

Implementation will require

isaacs commented 3 years ago

We could do the slow migration/pruning step should probably run whenever cacache.verify() is called. The cli runs this as part of npm doctor, but we can also tell the user to do it if cacache doesn't have the ref counting folder.

Also, we need to ensure that cacache still operates properly if ref counts are missing. I'd probably lean towards only updating ref counts if there is one already, and only add them for new items added to the cache, so we don't end up in a situation where it says "references: 1" for something that actually has a bunch of references on it.