Skip to content
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

add documentation for cache api on deploy #413

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions deploy/manual/edge-cache.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Edge Cache

:::caution Beta feature

Cache API support on Deno Deploy is currently in beta.

:::

The [Web Cache API](https://developer.mozilla.org/en-US/docs/Web/API/Cache) is
supported on Deno Deploy. The cache is designed to provide microsecond-level
read latency, multi-GB/s write throughput and unbounded storage, with the
tradeoff of best-effort consistency and durability.

```ts
const cache = await caches.open("my-cache");

Deno.serve(async (req) => {
const cached = await cache.match(req);
if (cached) {
return cached;
}

const res = new Response("cached at " + new Date().toISOString());
await cache.put(req, res.clone());
return res;
});
```

Cached data is stored in the same Deno Deploy region that runs your code.
Usually your isolate observes read-after-write (RAW) and write-after-write (WAW)
consistency within the same region; however, in rare cases recent writes can be
lost, out-of-order or temporarily invisible.

## Limitations

- The `Content-Length` header is required for cached requests.
- Deletion is not yet supported.
5 changes: 5 additions & 0 deletions sidebars/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ const sidebars = {
"kv/manual/cron",
],
},
{
type: "doc",
id: "manual/edge-cache",
label: "Edge Cache",
},
{
type: "html",
value: "<div>Connecting to Databases</div>",
Expand Down
Loading