-
Notifications
You must be signed in to change notification settings - Fork 24
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 me to control the cache time based on the fresh value #25
Comments
Sounds like a useful addition! I'm gonna have a look into this within the next days |
in order to support dynamically changing chage properties while getting the value fix #25
Could you give You can now patch the cache metadata during the getFreshValue call. cachified({
/* ... */
ttl: 5,
getFreshValue({ metadata }) {
metadata.ttl = 10;
return 'value'
}
}); |
Thanks for working on this so quickly! Hmmm... Interesting choice. Is there a reason you didn't go with making |
Yeah Multiple reasons. First and foremost doing it this way was a tiny change Secondly: The internal pending value cache also uses the ttl. This would have lead to a situation where a ttl-function would be called once with no value to determine the time other calls should wait for the same pending value and a second time once we have the value. Last but not least this might solve cases like #16 (cc @garand) where by overwriting the The approach might be a little more imperative then what you proposed but I like that in this case. In my mind it feels like initiating the call with a base set of assumptions and then while getting the fresh value we gain more knowledge and fine-tune some of our assumptions based on that. |
Just tried it out and it's great 👍 Thanks! |
Awesome! It's released now under |
Related to my use case in #24, if the user has a gravatar, then I'm happy to let that cache hang around for days. If they don't then I want to refresh it every 20 seconds. Maybe the
ttl
could accept a function which passes the current value if it's available and undefined if not?The text was updated successfully, but these errors were encountered: