Cache options interface

interface CacheConfig {
    duration: number;
    enabled: boolean;
    headersBlacklist: string[];
    prefixKey: string;
    statusCodes: { exclude: number[]; include: number[] };
    toggle: (
        req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>,
        res: Response<any, Record<string, any>>,
    ) => boolean;
    useBody: boolean;
}

Properties

duration: number

Default duration in seconds. Default: 10

enabled: boolean

Enablement flag. Default: true

headersBlacklist: string[]

List of header that should not be cached

prefixKey: string

Prefix key

statusCodes: { exclude: number[]; include: number[] }

List of status codes excluded and included

Type declaration

  • exclude: number[]

    Specifically Excluded status codes. Default: []

  • include: number[]

    Specifically Included status codes. Default: [200]

toggle: (
    req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>,
    res: Response<any, Record<string, any>>,
) => boolean

Toggle cache function. Takes the request/objects and must return a boolean value. If true, the response will be cached

useBody: boolean

Use request has as part of cache key