Logos DX
    Preparing search index...

    Interface CacheConfig<S, H, P>

    Configuration for response caching.

    Caching stores responses and returns cached values for identical requests, reducing API load and improving response times. Supports stale-while-revalidate (SWR) for background refresh.

    interface CacheConfig<S = unknown, H = unknown, P = unknown> {
        adapter?: CacheAdapter<unknown>;
        enabled?: boolean;
        methods?: _InternalHttpMethods[];
        rules?: CacheRule<unknown, unknown, unknown>[];
        serializer?: RequestSerializer<S, H, P>;
        skip?: (ctx: RequestKeyOptions<S, H, P>) => boolean;
        staleIn?: number;
        ttl?: number;
    }

    Type Parameters

    • S = unknown
    • H = unknown
    • P = unknown
    Index

    Properties

    adapter?: CacheAdapter<unknown>

    Custom cache adapter for external storage backends.

    Enables caching to Redis, IndexedDB, AsyncStorage, localStorage, etc. If omitted, uses in-memory MapCacheAdapter.

    // Redis adapter
    cachePolicy: {
    adapter: new RedisCacheAdapter(redisClient)
    }
    // localStorage adapter
    cachePolicy: {
    adapter: new LocalStorageCacheAdapter('api-cache')
    }
    enabled?: boolean

    Enable caching globally. Default: true

    HTTP methods to cache. Default: ['GET']

    rules?: CacheRule<unknown, unknown, unknown>[]

    Route-specific rules

    serializer?: RequestSerializer<S, H, P>

    Custom serializer for generating cache keys

    skip?: (ctx: RequestKeyOptions<S, H, P>) => boolean

    Skip caching based on request context. Return true to skip.

    staleIn?: number

    Time until stale for SWR (ms). Default: undefined (no SWR)

    ttl?: number

    Default TTL for cached responses (ms). Default: 60000