Skip to content

Commit 6438db1

Browse files
author
Jake Champion
committed
add documentation for KVStoreEntry and migration guide from v2 to v3
1 parent 9041319 commit 6438db1

File tree

48 files changed

+1059
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1059
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
8+
# KVStoreEntry.arrayBuffer()
9+
10+
The `arrayBuffer()` method of the `KVStoreEntry` interface takes a `KVStoreEntry` stream and reads it to completion. It returns a promise that resolves with an `ArrayBuffer`.
11+
## Syntax
12+
13+
```js
14+
text()
15+
```
16+
17+
### Parameters
18+
19+
None.
20+
21+
### Return value
22+
23+
A promise that resolves with an `ArrayBuffer`.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
8+
# KVStoreEntry.body
9+
10+
The `body` read-only property of the `KVStoreEntry` interface is a `ReadableStream` of the body contents.
11+
12+
## Value
13+
14+
A `ReadableStream`.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
8+
# KVStoreEntry.bodyUsed
9+
10+
The `bodyUsed` read-only property of the `KVStoreEntry` interface is a `boolean` value that indicates whether the body has been read yet.
11+
12+
## Value
13+
14+
A boolean value.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
8+
# KVStoreEntry.json()
9+
10+
The `json()` method of the `KVStoreEntry` interface takes a `KVStoreEntry` stream and reads it to completion. It returns a promise which resolves with the result of parsing the body text as JSON.
11+
12+
Note that despite the method being named `json()`, the result is not JSON but is instead the result of taking JSON as input and parsing it to produce a JavaScript object.
13+
14+
## Syntax
15+
16+
```js
17+
json()
18+
```
19+
20+
### Parameters
21+
22+
None.
23+
24+
### Return value
25+
26+
A `Promise` that resolves to a JavaScript object. This object could be anything that can be represented by JSON — an object, an array, a string, a number…
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
8+
# KVStoreEntry.text()
9+
10+
The `text()` method of the `KVStoreEntry` interface takes a `KVStoreEntry` stream and reads it to completion. It returns a promise that resolves with a `String`. The `KVStoreEntry `is always decoded using UTF-8.
11+
12+
## Syntax
13+
14+
```js
15+
text()
16+
```
17+
18+
### Parameters
19+
20+
None.
21+
22+
### Return value
23+
24+
A `Promise` that resolves with a `String`.

documentation/docs/migration-guide/index.mdx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,56 @@ hide_table_of_contents: false
55
pagination_next: null
66
pagination_prev: null
77
---
8+
9+
# `Migrating from v2 to v3`
10+
11+
## SimpleCache.delete renamed to SimpleCache.purge and requires purge options to be supplied as the second parameter
12+
13+
We are renaming because "purge" is already a well-known and documented concept for removing content from Fastly's cache.
14+
15+
The new addition of a second argument allows the caller to decide what scope to purge the content from, currently they can choose to purge from all of Fastly ("global") or from the POP that contains the currently executing instance ("pop"). We do not provide a default option right now, in the future we may provide a default option, if we discover a common pattern is being used.
16+
17+
Here is an example of migrating an application using `SimpleCache.delete` to `SimpleCache.purge` with the same purging behaviour:
18+
```diff
19+
/// <reference types="@fastly/js-compute" />
20+
21+
import { SimpleCache } from 'fastly:cache';
22+
23+
addEventListener('fetch', event => event.respondWith(app(event)));
24+
25+
async function app(event) {
26+
const url = new URL(event.request);
27+
const path = url.pathname;
28+
if (url.searchParams.has('delete')) {
29+
- SimpleCache.delete(path);
30+
+ SimpleCache.purge(path, { scope: "global" });
31+
return new Response(page, { status: 204 });
32+
}
33+
34+
let page = SimpleCache.getOrSet(path, async () => {
35+
return {
36+
value: await render(path),
37+
// Store the page in the cache for 1 minute.
38+
ttl: 60
39+
}
40+
});
41+
return new Response(page, {
42+
headers: {
43+
'content-type': 'text/plain;charset=UTF-8'
44+
}
45+
});
46+
}
47+
48+
async function render(path) {
49+
// expensive/slow function which constructs and returns the contents for a given path
50+
await new Promise(resolve => setTimeout(resolve, 10_000));
51+
return path;
52+
}
53+
54+
55+
```
56+
57+
858
# `Migrating from v1 to v2`
959

1060
## ObjectStore renamed to KVStore
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
8+
# KVStoreEntry.arrayBuffer()
9+
10+
The `arrayBuffer()` method of the `KVStoreEntry` interface takes a `KVStoreEntry` stream and reads it to completion. It returns a promise that resolves with an `ArrayBuffer`.
11+
## Syntax
12+
13+
```js
14+
text()
15+
```
16+
17+
### Parameters
18+
19+
None.
20+
21+
### Return value
22+
23+
A promise that resolves with an `ArrayBuffer`.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
8+
# KVStoreEntry.body
9+
10+
The `body` read-only property of the `KVStoreEntry` interface is a `ReadableStream` of the body contents.
11+
12+
## Value
13+
14+
A `ReadableStream`.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
8+
# KVStoreEntry.bodyUsed
9+
10+
The `bodyUsed` read-only property of the `KVStoreEntry` interface is a `boolean` value that indicates whether the body has been read yet.
11+
12+
## Value
13+
14+
A boolean value.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
hide_title: false
3+
hide_table_of_contents: false
4+
pagination_next: null
5+
pagination_prev: null
6+
---
7+
8+
# KVStoreEntry.json()
9+
10+
The `json()` method of the `KVStoreEntry` interface takes a `KVStoreEntry` stream and reads it to completion. It returns a promise which resolves with the result of parsing the body text as JSON.
11+
12+
Note that despite the method being named `json()`, the result is not JSON but is instead the result of taking JSON as input and parsing it to produce a JavaScript object.
13+
14+
## Syntax
15+
16+
```js
17+
json()
18+
```
19+
20+
### Parameters
21+
22+
None.
23+
24+
### Return value
25+
26+
A `Promise` that resolves to a JavaScript object. This object could be anything that can be represented by JSON — an object, an array, a string, a number…

0 commit comments

Comments
 (0)