-
Notifications
You must be signed in to change notification settings - Fork 0
/
axe.js
45 lines (35 loc) · 913 Bytes
/
axe.js
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
import axios from 'axios'
import path from 'path'
import cachios from 'cachios'
// cachios life hack
// { force: true } - for disable cache in axios request options
const CACHE_BACKEND = {
SQLITE: 'sqlite',
LEVELDB: 'leveldb',
}
const DEFAULT = {
folder: path.join(process.cwd(), '.cache'),
clear: false,
readonly: false,
backend: CACHE_BACKEND.SQLITE,
}
const init = async ({
folder = DEFAULT.folder,
clear = DEFAULT.clear,
readonly = DEFAULT.readonly,
backend = DEFAULT.backend,
} = DEFAULT) => {
cachios.getCacheIdentifier = (config) => ({
method: config.method,
url: config.url,
params: config.params,
data: config.data,
})
const ax = cachios.create(axios)
const { default: CacheLib } = await import(`./lib/${backend}.js`)
const cache = new CacheLib({ folder, clear, readonly })
await cache.init()
ax.cache = cache
return ax
}
export default init