Skip to main content
Version: 3.25.0

Migrating from v2 to v3

SimpleCache.delete renamed to SimpleCache.purge and requires purge options to be supplied as the second parameter

We are renaming because "purge" is already a well-known and documented concept for removing content from Fastly's cache.

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.

Here is an example of migrating an application using SimpleCache.delete to SimpleCache.purge with the same purging behaviour:

/// <reference types="@fastly/js-compute" />

import { SimpleCache } from 'fastly:cache';

addEventListener('fetch', event => event.respondWith(app(event)));

async function app(event) {
const url = new URL(event.request);
const path = url.pathname;
if (url.searchParams.has('delete')) {
- SimpleCache.delete(path);
+ SimpleCache.purge(path, { scope: "global" });
return new Response(page, { status: 204 });
}

let page = SimpleCache.getOrSet(path, async () => {
return {
value: await render(path),
// Store the page in the cache for 1 minute.
ttl: 60
}
});
return new Response(page, {
headers: {
'content-type': 'text/plain;charset=UTF-8'
}
});
}

async function render(path) {
// expensive/slow function which constructs and returns the contents for a given path
await new Promise(resolve => setTimeout(resolve, 10_000));
return path;
}


Migrating from v1 to v2

ObjectStore renamed to KVStore

We have renamed the ObjectStore class to KVStore, and the module name from fastly:object-store to fastly:kv-store.

You will need to update your code to use the new class name and module name.

Below is the change that would need to be made for the imported module name:

- import { ObjectStore } from 'fastly:object-store';
+ import { KVStore } from 'fastly:kv-store';

And this is the change that would need to be made for constructing an instance of the class:

- const store = new ObjectStore('my-store');
+ const store = new KVStore('my-store');

Here is a full example of migrating an application from ObjectStore to KVStore:

/// <reference types="@fastly/js-compute" />

- import { ObjectStore } from 'fastly:object-store';
+ import { KVStore } from 'fastly:kv-store';

async function app(event) {
- const files = new ObjectStore('files');
+ const files = new KVStore('files');

await files.put('hello', 'world')

const entry = await files.get('hello')

return new Response(await entry.text())
}

addEventListener("fetch", (event) => event.respondWith(app(event)))