axios-simple-cache-adapter
Version:
Configurable cache adapter for axios, works in the browser and node
72 lines (57 loc) • 2.21 kB
TypeScript
import { AxiosAdapter } from 'axios';
import { AxiosPromise } from 'axios';
import { AxiosResponse } from 'axios';
import { InternalAxiosRequestConfig } from 'axios';
export declare interface AsyncCacheManagerLikeCache {
get(key: string): Promise<string | null>;
set(key: string, value: string): Promise<any>;
del(key: string): Promise<any>;
}
export declare interface AsyncMapLikeCache {
get(key: string): Promise<string | null>;
set(key: string, value: string): Promise<any>;
delete(key: string): Promise<any>;
}
export declare interface AsyncStorageLikeCache {
getItem(key: string): Promise<string | null>;
setItem(key: string, value: string): Promise<any>;
removeItem(key: string): Promise<any>;
}
export declare interface AxiosCacheAdapter extends AxiosAdapter {
(config: AxiosCacheRequestConfig): AxiosPromise;
}
export declare interface AxiosCacheObject {
expiration: number;
value: AxiosResponse;
}
export declare interface AxiosCacheOptions {
debug?: boolean;
storage?: AxiosCacheStorage;
logger?: CacheLogger;
defaultTTL?: number;
parseHeaders?: boolean;
}
export declare interface AxiosCacheRequestConfig extends InternalAxiosRequestConfig {
cache?: boolean | number;
}
export declare type AxiosCacheStorage = StorageLikeCache | AsyncStorageLikeCache | MapLikeCache | AsyncMapLikeCache | CacheManagerLikeCache | AsyncCacheManagerLikeCache;
export declare interface CacheLogger {
log(message: string): void;
}
export declare interface CacheManagerLikeCache {
get(key: string): string | null;
set(key: string, value: string): void;
del(key: string): any;
}
export declare function createCacheAdapter({ debug, parseHeaders, logger, storage, defaultTTL, }?: AxiosCacheOptions): AxiosCacheAdapter;
export declare interface MapLikeCache {
get(key: string): string | null;
set(key: string, value: string): void;
delete(key: string): any;
}
export declare interface StorageLikeCache {
getItem(key: string): string | null;
setItem(key: string, value: string): any;
removeItem(key: string): any;
}
export { }