Skip to content

API Reference

Cache

Reference for BlurKitCache and built-in cache helpers.

Use cache integration when your job may encode the same source multiple times.

import { createFilesystemCache, encode } from 'blurkit/node'
const cache = createFilesystemCache({
dir: './.cache/blurkit',
ttlMs: 120_000,
})
const result = await encode('./public/hero.jpg', { cache })
interface BlurKitCache {
get(key: string): Promise<BlurResult | undefined> | BlurResult | undefined
set(key: string, value: BlurResult): Promise<void> | void
}

Built-in helpers:

  • createMemoryCache({ max? }) from blurkit/node and blurkit/deno
  • createFilesystemCache({ dir, ttlMs? }) from blurkit/node and blurkit/deno
  • createCloudflareCache({ name?, ttlSeconds? }) from blurkit/cloudflare
  • Cache keys are content-aware: they include a digest of the resolved image bytes plus every output-affecting option, so a changed file, Blob, or remote URL produces a new entry instead of stale output.
  • Memory cache is process-local and reset on restart.
  • Filesystem cache is local-disk scoped.
  • Cloudflare cache depends on Worker Cache API availability and scope.