cache.ts

Source

4 documented symbols. Read the signatures first, then expand each item for parameters, return types, and examples.

4 symbols 3 functions 1 modules 9 parameters 3 returns

Reference

modulecacheContent-hash based caching for OG images. Uses SHA256 of (template source + props + options) to determine if a re-rende…

Content-hash based caching for OG images.

Uses SHA256 of (template source + props + options) to determine if a re-render is needed. Cache dir: .cache/og-images

View source

fncomputeCacheKey(templateSource: string, props: Record<string, unknown>, width: number, height: number): stringComputes a cache key from template + props + options.

Computes a cache key from template + props + options.

Signature

export function computeCacheKey(templateSource: string, props: Record<string, unknown>, width: number, height: number): string

View source

Parameters

  • templateSource string
  • props Record<string, unknown>
  • width number
  • height number

Returns

string
fngetCached(cacheDir: string, key: string): Promise<Buffer | null>Checks if a cached PNG exists for the given key. Returns the cached file path i…

Checks if a cached PNG exists for the given key. Returns the cached file path if found, null otherwise.

Signature

export async function getCached(cacheDir: string, key: string): Promise<Buffer | null>

View source

Parameters

  • cacheDir string
  • key string

Returns

Promise<Buffer | null>
fnwriteCache(cacheDir: string, key: string, png: Buffer): Promise<void>Writes a PNG buffer to the cache.

Writes a PNG buffer to the cache.

Signature

export async function writeCache(cacheDir: string, key: string, png: Buffer): Promise<void>

View source

Parameters

  • cacheDir string
  • key string
  • png Buffer

Returns

Promise<void>