Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

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

Open
jfmartinez opened this issue Jul 10, 2017 · 2 comments
Open

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

jfmartinez opened this issue Jul 10, 2017 · 2 comments

Comments

@jfmartinez
Copy link
Contributor

jfmartinez commented Jul 10, 2017

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!

@zkat zkat added the support label Jul 10, 2017
@zkat
Copy link
Owner

zkat commented Jul 10, 2017

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.

@zkat
Copy link
Owner

zkat commented Jul 23, 2017

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants