Skip to content

API reference

cache(options) creates a Layeron cache module for edge response caching, invalidation tags, route rules, and runtime cache operations.

Terminal window
import { cache } from "@layeron/modules"

Create a Layeron cache module.

Terminal window
cache(options: CacheModuleOptions): CacheModule

Bypass conditions for one cache rule.

FieldTypeDescription
headersstring[] | undefinedRequest headers that bypass this cache rule when present.
cookiesstring[] | undefinedCookie names that bypass this cache rule when present.
querystring[] | undefinedQuery parameter names that bypass this cache rule when present.

Route-level cache policy.

FieldTypeDescription
namestring | undefinedStable rule name. Layeron generates one when omitted.
pathstring | undefinedPath pattern matched by the gateway.
methodsstring[] | undefinedHTTP methods covered by this rule.
ttlSecondsint32 | undefinedFresh cache lifetime in seconds.
staleWhileRevalidateSecondsint32 | undefinedSeconds a stale response may be served while revalidation runs.
varystring[] | undefinedRequest dimensions included in the cache key.
tagsstring[] | undefinedInvalidation tags attached to responses written by this rule.
bypassCacheBypassOptions | undefinedConditions that bypass this rule.

Options accepted by cache(options).

FieldTypeDescription
namestringStable cache instance name inside the Layeron app.
namespacestring | undefinedPlatform namespace for the instance. Defaults to default.
ttlSecondsint32 | undefinedDefault fresh cache lifetime in seconds.
staleWhileRevalidateSecondsint32 | undefinedDefault stale-while-revalidate window in seconds.
varystring[] | undefinedDefault request dimensions included in cache keys.
tagsstring[] | undefinedDefault invalidation tags attached to responses.
rulesCacheRuleOptions[] | undefinedRoute-level cache rules.
observabilityLayeron.Observability.ObservabilityConfig | undefinedObservability settings for cache hits, misses, writes, and purges.

Options used when computing a cache key.

FieldTypeDescription
namespacestring | undefinedPlatform namespace for the instance. Defaults to default.
tagsstring[] | undefinedInvalidation tags attached to entries written with these options. Tags are metadata for purge operations and stay outside cache-key partitioning.
varystring[] | undefinedRequest dimensions included in the key.

Input accepted by cache.purge().

FieldTypeDescription
requeststring | undefinedSpecific request URL or key to purge.
tagsstring[] | undefinedTags to purge.
prefixstring | undefinedKey prefix to purge.

Result returned by cache.purge().

FieldTypeDescription
purgedint32Number of cache entries purged.

Cache runtime counters.

FieldTypeDescription
hitsint32Number of cache hits.
missesint32Number of cache misses.
putsint32Number of cache writes.
deletesint32Number of cache deletes.
purgesint32Number of purge operations.

Layeron cache module returned by cache(options).

FieldTypeDescription
name”cache”Module name.
configCacheModuleOptionsNormalized module configuration.
observabilityLayeron.Observability.ObservabilityConfig | undefinedEffective observability policy recorded on the module declaration.

Compute the cache key for a request.

Terminal window
cacheKey(request: string, options?: CacheKeyOptions): string

Delete cache entries by request, tag, or prefix.

Terminal window
cachePurge(input?: CachePurgeInput): CachePurgeResult

Read cache runtime counters.

Terminal window
cacheStats(): CacheStats