-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: kv binding support for suspense cache (#548)
- Loading branch information
1 parent
f364224
commit 888ae85
Showing
9 changed files
with
94 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
'@cloudflare/next-on-pages': minor | ||
--- | ||
|
||
Add support for using a KV to implement the Suspense Cache via naming convention | ||
|
||
With this change users can have their suspense cache implemented via a KV binding, in order to | ||
opt-in to such implementation they simply need to make sure that their application has a KV binding | ||
named `__NEXT_ON_PAGES__KV_SUSPENSE_CACHE` (the next-on-pages worker will pick up such | ||
binding and use it to implement the suspense cache instead of using the default workers cache API). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { CacheAdaptor } from './adaptor.js'; | ||
|
||
/** Suspense Cache adaptor for Workers KV. */ | ||
export default class KVAdaptor extends CacheAdaptor { | ||
constructor(ctx: Record<string, unknown> = {}) { | ||
super(ctx); | ||
} | ||
|
||
public override async retrieve(key: string) { | ||
const value = await process.env.__NEXT_ON_PAGES__KV_SUSPENSE_CACHE?.get( | ||
this.buildCacheKey(key), | ||
); | ||
|
||
return value ?? null; | ||
} | ||
|
||
public override async update(key: string, value: string) { | ||
await process.env.__NEXT_ON_PAGES__KV_SUSPENSE_CACHE?.put( | ||
this.buildCacheKey(key), | ||
value, | ||
); | ||
} | ||
} |