This repository has been archived by the owner on Feb 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 107
/
axios-cache-adapter.d.ts
151 lines (137 loc) · 4.15 KB
/
axios-cache-adapter.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* Created by user on 2019/5/12.
*/
import { AxiosInstance, AxiosRequestConfig, AxiosAdapter } from 'axios';
declare module 'axios'
{
interface AxiosRequestConfig
{
/**
* configure how the cached requests will be handled, where they will be stored, etc.
*/
cache?: IAxiosCacheAdapterOptions;
/**
* force cache invalidation
*/
clearCacheEntry?: boolean;
}
}
/**
* configure how the cached requests will be handled, where they will be stored, etc.
*/
export interface IAxiosCacheAdapterOptions
{
/**
* {Number} Maximum time for storing each request in milliseconds,
* defaults to 15 minutes when using `setup()`.
*/
maxAge?: number;
/**
* {Number} Maximum number of cached request (last in, first out queue system),
* defaults to `false` for no limit. *Cannot be overridden per request*
*/
limit?: false | number;
/**
* {Object} An instance of localforage, defaults to a custom in memory store.
* *Cannot be overridden per request*
*/
store?: object;
/**
* {String|Function} Generate a unique cache key for the request.
* Will use request url and serialized params by default.
*/
key?(req: AxiosRequestConfig): string;
/**
* {Function} Invalidate stored cache. By default will remove cache when
* making a `POST`, `PUT`, `PATCH` or `DELETE` query.
*/
invalidate?(cfg: IAxiosCacheAdapterOptions, req: AxiosRequestConfig): Promise<void>;
/**
* {Object} Define which kind of requests should be excluded from cache.
*/
exclude?: {
/**
* {Array} List of regular expressions to match against request URLs.
*/
paths?: RegExp[];
/**
* {Boolean} Exclude requests with query parameters.
*/
query?: boolean;
/**
* {Function} Method which returns a `Boolean` to determine if request
* should be excluded from cache.
*/
filter?: Function;
/**
* {Array} HTTP methods which will be excluded from cache.
* Defaults to `['post', 'patch', 'put', 'delete']`
* Any methods listed will also trigger cache invalidation while using the default `config.invalidate` method.
*
* Note: the HEAD method is always excluded (hard coded).
*/
methods?: ('get' | 'post' | 'patch' | 'put' | 'delete')[];
};
/**
* {Boolean} Clear cached item when it is stale.
*/
clearOnStale?: boolean;
/**
* {Boolean} Clear all cache when a cache write error occurs
* (prevents size quota problems in `localStorage`).
*/
clearOnError?: boolean;
/**
* {Function|Boolean} Determine if stale cache should be read when a network error occurs.
*/
readOnError?: Function | boolean;
/**
* {Boolean} Determine if response headers should be read to set `maxAge` automatically.
* Will try to parse `cache-control` or `expires` headers.
*/
readHeaders?: boolean;
/**
* {Boolean} Ignore cache, will force to interpret cache reads as a `cache-miss`.
* Useful to bypass cache for a given request.
*/
ignoreCache?: boolean;
/**
* {Function|Boolean} Print out debug log to console.
*/
debug?: Function | boolean;
excludeFromCache?: boolean;
}
export interface ISetupCache
{
adapter: AxiosAdapter;
config: IAxiosCacheAdapterOptions;
store: object;
}
/**
* Create an axios instance pre-configured with the cache adapter. Takes an options object to configure the cache and axios at the same time.
* @param {AxiosRequestConfig} options
* @returns {AxiosInstance}
*/
export declare function setup(options: AxiosRequestConfig): AxiosInstance;
/**
* Create a cache adapter instance. Takes an options object to configure how the cached requests will be handled, where they will be stored, etc.
*/
export declare function setupCache(options: IAxiosCacheAdapterOptions) : ISetupCache;
export class RedisStore { constructor(client: any, HASH_KEY?: string); }
export interface RedisDefaultOptions
{
prefix?: String;
maxScanCount?: number;
}
export class RedisDefaultStore { constructor(client: any, options?: RedisDefaultOptions); }
export interface IAxiosCacheAdapterRequest
{
/**
* When a response is served from cache a custom `response.request` object is created with a `fromCache` boolean.
*/
fromCache?: boolean,
/**
* Check that query was excluded from cache
*/
excludedFromCache?: boolean,
}