Skip to content

cache.ts#

View Markdown

Source

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

5 symbols 4 functions 1 modules 11 parameters 4 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>
fnisCached(cacheDir: string, key: string): Promise<boolean>Whether a cached PNG exists, without reading it. Deciding whether the browser h…

Whether a cached PNG exists, without reading it.

Deciding whether the browser has to start at all only needs to know that every key is present. Reading each file to answer that costs a full pass over the cache before rendering has begun.

Signature

export async function isCached(cacheDir: string, key: string): Promise<boolean>

View source

Parameters

  • cacheDir string
  • key string

Returns

Promise<boolean>
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>