zkat / cacache

💩💵 but for your data. If you've got the hash, we've got the cache ™ (moved)

Home Page:https://github.com/npm/cacache

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can the metadata of an entry be updated on a 'get' call?

jfmartinez opened this issue · comments

Hello!

I was wondering if it was possible to update the metadata of an entry without having to write it out again. Basically, I want to keep track of the access time of an entry and maintaining it in the metadata was my initial thought.

Appreciate the help in advance!

P.S. I tried updating the label but I do not have access to. Thanks!

So, the entry index (which is where the metadata exists), is append-only -- this means that every time you insert something, or even call the index writer -- you append. You probably don't want to keep something as frequently-modified as an atime in there.

If you still want to do it this way, though, I have some recommendations:

  1. You can create another entry keyed by the SRI of the data you're referencing, and write an empty string to it on top of the metadata. This is kinda hacky, but can be pretty useful depending on what you want.

  2. You can directly use require('cache/lib/entry-index.js').insert and write out your own entries -- this is technically an internal API, but it's about as stable as anything else in cacache is going to be. I've considered adding a toplevel interface for index.insert() that mirrors cacache.get.info, but I've never found any real use for it that I thought was important: the data that cacache was designed for is generally fairly immutable, so avoiding that complexity at the interface level seemed like a good idea.

I know I'm not the only user of cacache (which is cool!) and I don't think adding the ability to append metadata to the index is a bad idea. I would actually accept a community patch that exposed index.insert() with some interface-side safety checks (such as enforcement that the contents for some metadata are present, maybe? Or at least a bit more verification for arguments). That would probably serve your needs well enough?

One final note: If you're doing this a lot, I recommend you run an occasional verify() to prune the index buckets -- depending on how often you do this, they might get quite big, and cacache doesn't trim them automatically, even if shadowed.

Gonna mark this as something I'll take a PR for 👍