Expose the internal cache
function used by the "use cache"
directive
#75645
sannajammeh
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
I don't know the details of your SDK, but if you're writing some support for a next.js-specific API anyway (AFAIK nothing else uses an API like |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Non-Goals
Background
The
unstable_cache
function works great, but as you know it requires the tags and keyparts to be defined ahead of time.From my understanding the
cache
function used internally byuseCache
runs through ALS. Meaning the features exposed by"use cache"
likecacheTag
&cacheLife
are still usable with this.We author several SDK's and fetch libraries. With
"use cache"
all caching must be handled by the consumers, but it doesn't have to be this way.Our current libraries accept a cache function:
Meaning each call to
sdk.getUser("bob")
can be automatically tagged withuser:bob
and invalidated automatically.This makes webhook calls a breeze as we also only expose a single revalidate endpoint
And thats it. Our consumers now don't have to think about caching, at all.
Proposal
My proposal is simple as the underlying unstable_cache gets deprecated:
Expose the internal ALS powered cache function directly. Either by calling it cache or something more discrete to discourage users
createCacheScope
.Our SDK would then look like so:
Interally this now happens:
cache
user:bob
Beta Was this translation helpful? Give feedback.
All reactions