Skip to content

Commit

Permalink
Expose caches to Cloudflare adapter through Platform (#5081)
Browse files Browse the repository at this point in the history
* Expose `caches` to Cloudflare adapter

* Add changeset
  • Loading branch information
venashial authored Jul 6, 2022
1 parent b0ef393 commit 320777a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-bees-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-cloudflare': minor
---

Expose Cloudflare Worker Cache API through `caches` in Platform
5 changes: 3 additions & 2 deletions packages/adapter-cloudflare/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ When configuring your project settings, you must use the following settings:
## Environment variables

The [`env`](https://developers.cloudflare.com/workers/runtime-apis/fetch-event#parameters) object, containing KV namespaces etc, is passed to SvelteKit via the `platform` property along with `context`, meaning you can access it in hooks and endpoints:
The [`env`](https://developers.cloudflare.com/workers/runtime-apis/fetch-event#parameters) object, containing KV namespaces etc, is passed to SvelteKit via the `platform` property along with `context` and `caches`, meaning you can access it in hooks and endpoints:

```diff
// src/app.d.ts
Expand All @@ -66,7 +66,8 @@ declare namespace App {
+ };
+ context: {
+ waitUntil(promise: Promise<any>): void;
+ }
+ };
+ caches: CacheStorage & { default: Cache }
+ }

interface Session {}
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-cloudflare/src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const worker = {
} else {
// dynamically-generated pages
res = await server.respond(req, {
platform: { env, context },
platform: { env, context, caches },
getClientAddress() {
return req.headers.get('cf-connecting-ip');
}
Expand Down

0 comments on commit 320777a

Please sign in to comment.