Vercel
#Vercel Runtime Cache
Cache data within Vercel Functions using the Runtime Cache API.
Read more in vercel.com/docs/functions.
#Usage
Driver name: vercel-runtime-cache
import { createStorage } from "unstorage";
import vercelRuntimeCacheDriver from "unstorage/drivers/vercel-runtime-cache";
const storage = createStorage({
driver: vercelRuntimeCacheDriver({
// base: "app",
// ttl: 60, // seconds
tags: ["v1"],
}),
});Optional step: To allow using outside of vercel functions, install @vercel/functions in your project:
npm i @vercel/functions#Options
base: Optional prefix to use for all keys (namespacing).ttl: Default TTL for all items in seconds.tags: Default tags to apply to all cache entries (Note: Will be merged with per-call option tags).
#Per-call options
ttl: Add TTL (in seconds) for thissetItemcall.tags: Apply tags to thissetItemcall.
Example:
await storage.setItem("user:123", JSON.stringify({ name: "Ana" }), {
ttl: 3600,
tags: ["user:123"],
});To expire by tags:
await storage.clear();#Limitations
getKeys: The runtime cache API does not support listing keys; this returns[].clear: The runtime cache API does not support clearing by base. It expires the defaulttagsconfigured on the driver; per-call clear options are not supported.- Metadata: Runtime cache does not expose metadata;
getMetais not implemented. - Persistence: This is not a persistent store; it’s intended for request-time caching inside Vercel Functions.
Note
The unstorage driver does not hash keys by default. To reproduce that behavior when calling getCache from @vercel/functions directly, set keyHashFunction: (key) => key.
#Vercel Blob
Store data in a Vercel Blob Store.
Read more in vercel.com/docs/storage/vercel-blob.
#Usage
Driver name: vercel-blob
To use, you will need to install @vercel/blob dependency in your project:
npm i @vercel/blob#Public access
Public blobs are accessible via their URL without authentication.
import { createStorage } from "unstorage";
import vercelBlobDriver from "unstorage/drivers/vercel-blob";
const storage = createStorage({
driver: vercelBlobDriver({
access: "public",
// token: "<your secret token>", // or set BLOB_READ_WRITE_TOKEN
// base: "unstorage",
// envPrefix: "BLOB",
}),
});#Private access
Private blobs require authentication to access. You need to create a private blob store on the Vercel dashboard before using this mode.
import { createStorage } from "unstorage";
import vercelBlobDriver from "unstorage/drivers/vercel-blob";
const storage = createStorage({
driver: vercelBlobDriver({
access: "private",
// token: "<your secret token>", // or set BLOB_READ_WRITE_TOKEN
// base: "unstorage",
// envPrefix: "BLOB",
}),
});#Options
access: Whether the blob should be publicly or privately accessible. Must be"public"or"private".base: Prefix to prepend to all keys. Can be used for namespacing.token: REST API token for the Vercel Blob store. When omitted, it is read fromBLOB_READ_WRITE_TOKEN.envPrefix: Prefix to use for token environment variable name. Default isBLOB(env name =BLOB_READ_WRITE_TOKEN).