edge-master
Version:
A Micro Framework for Edges
57 lines (56 loc) • 1.69 kB
TypeScript
/// <reference types="@cloudflare/workers-types" />
import { IRequestInterceptor, IResponseInterceptor } from '../types/interceptor';
export interface CacheOptions {
/**
* Cache TTL in seconds
* @default 3600 (1 hour)
*/
ttl?: number;
/**
* Custom cache key generator
* @default URL of the request
*/
cacheKey?: (req: Request) => string;
/**
* Cache control header value
*/
cacheControl?: string;
/**
* Whether to cache only GET requests
* @default true
*/
cacheGetOnly?: boolean;
/**
* Function to determine if a response should be cached
* @default Only cache 200 responses
*/
shouldCache?: (req: Request, res: Response) => boolean;
/**
* Cache name (for Cloudflare)
* @default 'default'
*/
cacheName?: string;
}
/**
* Creates a request interceptor that checks the cache
*/
export declare function cacheCheckInterceptor(options?: CacheOptions): IRequestInterceptor;
/**
* Creates a response interceptor that stores responses in cache
*/
export declare function cacheStoreInterceptor(options?: CacheOptions): IResponseInterceptor;
/**
* Creates both cache check and store interceptors
*/
export declare function cacheInterceptor(options?: CacheOptions): {
check: IRequestInterceptor;
store: IResponseInterceptor;
};
/**
* Helper to generate cache keys based on URL and query parameters
*/
export declare function cacheKeyFromUrl(req: Request, includeQuery?: boolean): string;
/**
* Helper to generate cache keys based on URL and specific query parameters
*/
export declare function cacheKeyWithParams(req: Request, params: string[]): string;