Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a validation function for retrieving cached values #13

Open
jkrems opened this issue Feb 26, 2015 · 7 comments
Open

Allow a validation function for retrieving cached values #13

jkrems opened this issue Feb 26, 2015 · 7 comments

Comments

@jkrems
Copy link
Contributor

jkrems commented Feb 26, 2015

There should be an optional validation function for get and getOrElse operation. If the data fails the validation function, it should count as a cache miss. If the validation function throws, it should count as a get error.

@jkrems
Copy link
Contributor Author

jkrems commented Feb 26, 2015

For getOrElse the validation function should also be run on values that are to be stored.

@johan
Copy link

johan commented Mar 10, 2015

This is something we want too, and consider addressing in a bit, as we have a fair deal of semantically (if not technically) empty responses that take a while to flush out of our caches at the moment.

@ghost
Copy link

ghost commented Mar 10, 2015

What if the getOrElse lambda returns null/undefined and that counts as a validation failure?

@jkrems
Copy link
Contributor Author

jkrems commented Mar 10, 2015

null is a valid value to cache. E.g. to cache a missing value (when checking for existence is expensive). It's also about validation the value that comes from the cache - not the only the generated value.

@johan
Copy link

johan commented Mar 10, 2015

Am I missing something, for thinking that the current call signature (getOrElse(rawKey, val, opts, cb)) doesn't yet pass the proposed validation function, and that on adding one here, it would just return a boolean value to pass or fail the value it tests? It seems like just adding an opts.validate or something should be straight-forward.

Or is @khoomeister talking about a presenter function that lets us condense the api call value and save something parsed in the cache instead of the literal response – with overloaded behaviour semantics for letting, say, undefined signal error?

Something like that (with a clean api) would be useful too, but perhaps as its own independent feature. I have specifically wanted to cache not just the response body, but also bits from response metadata passed in subsequent callback args from request, or gofer.fetch, like what the api url was, so getOrElse could pass on as many callback args for the cached case as for the non-cached case.

@jkrems
Copy link
Contributor Author

jkrems commented Mar 10, 2015

@johan Yes, opts.validate was what I had in mind. I'm hesitant to add something with more complex semantics than "check schema, return boolean". Especially mapping/transforming the data seems like overstepping boundaries for a caching library. The direction for everything right now is "promises", so I don't think adding features that refer to callback semantics makes sense at this point.

@ghost
Copy link

ghost commented Mar 10, 2015

cool @jkrems, i was more concerned with how much validation functionality to include 😃 - your proposed interface sounds good to me.

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

No branches or pull requests

2 participants