1.5.2 • Published 2 years ago
@prequest/cache v1.5.2
@prequest/cache
缓存器。
安装
npm install @prequest/cache
使用
下面的示例表示在一分钟内,发起的相同的路径的 GET 请求,都只会调用一次接口,响应相同的数据。
import { create } from '@prequest/xhr'
import createCacheAdapter from '@prequest/cache'
const cache = createCacheAdapter({
ttl: 60000,
getCacheKey: opt => opt.path,
verifyRequest: opt => !opt.method || opt.method === 'GET',
verifyResponse: res => {
if (res.status === 200) return res.data
throw 'http error'
},
})
const prequest = create({ useCache: true }, cache)
配置项
Option Name | Type | Default | Required | Meaning |
---|---|---|---|---|
ttl | number | 60000 | false | 默认一分钟缓存失效 |
getCacheKey | (opt: any) => string | (opt) => opt.path | false | 默认以请求路径作为缓存的 key |
verifyRequest | (opt: any) => boolean | opt => !opt.method || opt.method === 'GET' | false | 默认 GET 请求才会缓存 |
verifyResponse | (res: any) => any | res => res | false | 默认 GET 请求才会缓存 |
同时,发起请求时,设置 useCache
为 true
,且 verifyRequest
校验通过,则会缓存请求数据。
1.5.2
2 years ago
1.5.1
2 years ago
1.5.0
2 years ago
1.3.7
2 years ago
1.3.6
2 years ago
1.4.1
2 years ago
1.4.0
2 years ago
1.3.10
2 years ago
1.3.9
2 years ago
1.3.8
2 years ago
1.3.5
2 years ago
1.3.3
2 years ago
1.3.2
2 years ago
1.3.3-alpha.0
2 years ago
1.2.6
2 years ago
1.2.4
3 years ago
1.2.0
3 years ago
1.1.1
3 years ago
1.1.4
3 years ago
1.1.3
3 years ago
1.2.1
3 years ago
1.1.2
3 years ago
1.1.0
3 years ago
1.0.4
3 years ago
1.0.3
3 years ago
1.0.1
3 years ago
1.0.1-alpha.0
3 years ago
1.0.0-alpha.0
3 years ago
0.4.7
3 years ago
0.4.5
3 years ago
0.4.4
3 years ago
0.4.6
3 years ago
0.4.3
3 years ago
0.4.2
3 years ago
0.3.2
3 years ago
0.4.0
3 years ago
0.3.0
3 years ago
0.2.7
3 years ago
0.2.8
3 years ago
0.2.6
3 years ago
0.2.5
3 years ago
0.2.4
3 years ago