You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to set a cache's maxAge according to the value that is returned by the memoized function?
I am fetching an OAuth access token which has an expires_in value, and I would like to cache the token for approximately as long as it is valid. The problem is that the value of expires_in is set by the remote auth server and is unknown until I actually fetch the token.
The text was updated successfully, but these errors were encountered:
Is it possible to set a cache's maxAge according to the value that is returned by the memoized function?
Unfortunately not; it is a configuration option for the cache, and is therefore static for the life of that function. However, you may be able to manually implement a manual cache removal by using some of the lifecycle methods.
If you leverage the onCacheAdd method to manually trigger a deletion with a setTimeout whenever a new value is added to the cache. A pseudo-code example:
If you wanted the value to reset when the cache was hit you'll likely need to get more creative (managing your own key => timeoutId cache to clear and restart the timeout), but something like this may give you what you seek. The maxAge option is basically just an automated version of this with some performance tweaks.
Is it possible to set a cache's
maxAge
according to the value that is returned by the memoized function?I am fetching an OAuth access token which has an
expires_in
value, and I would like to cache the token for approximately as long as it is valid. The problem is that the value ofexpires_in
is set by the remote auth server and is unknown until I actually fetch the token.The text was updated successfully, but these errors were encountered: