Skip to main content

Cache Manager API Reference

The Cache Manager provides a unified interface for various caching strategies and backends optimized for edge environments.

CacheManager

Main cache management class supporting multiple backends and strategies.

Constructor

Parameters:
  • options (object): Cache configuration options
Options:
  • backend (string): Cache backend (‘memory’, ‘redis’, ‘cloudflare-kv’)
  • ttl (number): Default TTL in milliseconds
  • maxSize (number): Maximum cache size
  • strategy (string): Eviction strategy (‘lru’, ‘lfu’, ‘fifo’)
  • compression (boolean): Enable compression
  • namespace (string): Cache namespace

Methods

get(key, options)

Retrieve a value from cache.
Parameters:
  • key (string): Cache key
  • options (object, optional): Get options
Returns: Promise resolving to cached value or undefined

set(key, value, options)

Store a value in cache.
Parameters:
  • key (string): Cache key
  • value (any): Value to cache
  • options (object, optional): Set options

delete(key)

Remove a value from cache.
Parameters:
  • key (string): Cache key

clear()

Clear all cached values.

has(key)

Check if key exists in cache.
Parameters:
  • key (string): Cache key
Returns: Promise resolving to boolean

getStats()

Get cache statistics.
Returns: Promise resolving to statistics object

memoize(fn, options)

Create a memoized version of a function.
Parameters:
  • fn (function): Function to memoize
  • options (object, optional): Memoization options
Returns: Memoized function

Cache Strategies

LRU (Least Recently Used)

LFU (Least Frequently Used)

FIFO (First In, First Out)

Cache Backends

Memory Backend

Redis Backend

Cloudflare KV Backend

Cache Patterns

Read-Through Caching

Write-Through Caching

Cache-Aside Pattern

Type Definitions

CacheOptions

CacheStats

MemoizeOptions