API reference
cache(options) creates a Layeron cache module for edge response caching, invalidation tags, route rules, and runtime cache operations.
Import
Section titled “Import”import { cache } from "@layeron/modules"Create a Layeron cache module.
cache(options: CacheModuleOptions): CacheModuleCacheBypassOptions
Section titled “CacheBypassOptions”Bypass conditions for one cache rule.
| Field | Type | Description |
|---|---|---|
headers | string[] | undefined | Request headers that bypass this cache rule when present. |
cookies | string[] | undefined | Cookie names that bypass this cache rule when present. |
query | string[] | undefined | Query parameter names that bypass this cache rule when present. |
CacheRuleOptions
Section titled “CacheRuleOptions”Route-level cache policy.
| Field | Type | Description |
|---|---|---|
name | string | undefined | Stable rule name. Layeron generates one when omitted. |
path | string | undefined | Path pattern matched by the gateway. |
methods | string[] | undefined | HTTP methods covered by this rule. |
ttlSeconds | int32 | undefined | Fresh cache lifetime in seconds. |
staleWhileRevalidateSeconds | int32 | undefined | Seconds a stale response may be served while revalidation runs. |
vary | string[] | undefined | Request dimensions included in the cache key. |
tags | string[] | undefined | Invalidation tags attached to responses written by this rule. |
bypass | CacheBypassOptions | undefined | Conditions that bypass this rule. |
CacheModuleOptions
Section titled “CacheModuleOptions”Options accepted by cache(options).
| Field | Type | Description |
|---|---|---|
name | string | Stable cache instance name inside the Layeron app. |
namespace | string | undefined | Platform namespace for the instance. Defaults to default. |
ttlSeconds | int32 | undefined | Default fresh cache lifetime in seconds. |
staleWhileRevalidateSeconds | int32 | undefined | Default stale-while-revalidate window in seconds. |
vary | string[] | undefined | Default request dimensions included in cache keys. |
tags | string[] | undefined | Default invalidation tags attached to responses. |
rules | CacheRuleOptions[] | undefined | Route-level cache rules. |
observability | Layeron.Observability.ObservabilityConfig | undefined | Observability settings for cache hits, misses, writes, and purges. |
CacheKeyOptions
Section titled “CacheKeyOptions”Options used when computing a cache key.
| Field | Type | Description |
|---|---|---|
namespace | string | undefined | Platform namespace for the instance. Defaults to default. |
tags | string[] | undefined | Invalidation tags attached to entries written with these options. Tags are metadata for purge operations and stay outside cache-key partitioning. |
vary | string[] | undefined | Request dimensions included in the key. |
CachePurgeInput
Section titled “CachePurgeInput”Input accepted by cache.purge().
| Field | Type | Description |
|---|---|---|
request | string | undefined | Specific request URL or key to purge. |
tags | string[] | undefined | Tags to purge. |
prefix | string | undefined | Key prefix to purge. |
CachePurgeResult
Section titled “CachePurgeResult”Result returned by cache.purge().
| Field | Type | Description |
|---|---|---|
purged | int32 | Number of cache entries purged. |
CacheStats
Section titled “CacheStats”Cache runtime counters.
| Field | Type | Description |
|---|---|---|
hits | int32 | Number of cache hits. |
misses | int32 | Number of cache misses. |
puts | int32 | Number of cache writes. |
deletes | int32 | Number of cache deletes. |
purges | int32 | Number of purge operations. |
CacheModule
Section titled “CacheModule”Layeron cache module returned by cache(options).
| Field | Type | Description |
|---|---|---|
name | ”cache” | Module name. |
config | CacheModuleOptions | Normalized module configuration. |
observability | Layeron.Observability.ObservabilityConfig | undefined | Effective observability policy recorded on the module declaration. |
Operations
Section titled “Operations”cacheKey
Section titled “cacheKey”Compute the cache key for a request.
cacheKey(request: string, options?: CacheKeyOptions): stringcachePurge
Section titled “cachePurge”Delete cache entries by request, tag, or prefix.
cachePurge(input?: CachePurgeInput): CachePurgeResultcacheStats
Section titled “cacheStats”Read cache runtime counters.
cacheStats(): CacheStats