1.0.57 • Published 3 years ago
axios-cache-adapter-util v1.0.57
README
axios-cache-adapter export/import json for save/load file
yarn add axios axios-cache-adapter fs-extra axios-cache-adapter-util
import { setupCache, ISetupCache } from 'axios-cache-adapter';
import Axios, { AxiosAdapter } from 'axios';
import { exportCache, importCache, processExitHook } from '../lib/index';
import fs from 'fs-extra';
import path from 'path';
(async () => {
const saveCacheFileBySelf = true;
let cache = setupCache({
maxAge: 15 * 60 * 1000,
});
const cacheFile = path.join(__dirname, 'temp', 'axios.cache.json');
await fs.readJSON(cacheFile)
.catch(e => {
return {}
})
.then(async (json) => {
let len = await cache.store.length();
await importCache(cache.store, json);
let len2 = await cache.store.length();
console.log(`before: ${len}`, `after: ${len2}`);
})
;
function saveCache()
{
return exportCache(cache.store, (json) => {
fs.outputJSONSync(cacheFile, json, {
spaces: 2,
});
console.debug(`[Cache]`, Object.keys(json).length, `saved`, cacheFile);
})
}
if (!saveCacheFileBySelf)
{
await processExitHook(() => {
return saveCache();
});
}
let axios = Axios.create({
adapter: cache.adapter as AxiosAdapter
});
await axios.get('https://github.com/RasCarlito/axios-cache-adapter')
.then((ret) => {
console.log(ret.status, ret.statusText);
//console.dir(ret.headers);
})
;
if (saveCacheFileBySelf)
{
await saveCache();
}
})();
1.0.57
3 years ago
1.0.56
3 years ago
1.0.55
3 years ago
1.0.54
3 years ago
1.0.53
3 years ago
1.0.52
3 years ago
1.0.51
3 years ago
1.0.50
3 years ago
1.0.49
3 years ago
1.0.48
3 years ago
1.0.46
3 years ago
1.0.45
4 years ago
1.0.44
4 years ago
1.0.43
4 years ago
1.0.42
4 years ago
1.0.41
4 years ago
1.0.39
4 years ago
1.0.38
4 years ago
1.0.37
4 years ago
1.0.36
4 years ago
1.0.35
4 years ago
1.0.33
4 years ago
1.0.34
4 years ago
1.0.32
4 years ago
1.0.31
4 years ago
1.0.30
4 years ago
1.0.28
4 years ago
1.0.27
4 years ago
1.0.26
4 years ago
1.0.25
4 years ago
1.0.24
4 years ago
1.0.23
4 years ago
1.0.22
4 years ago
1.0.19
4 years ago
1.0.20
4 years ago
1.0.18
4 years ago
1.0.17
5 years ago
1.0.16
5 years ago
1.0.12
5 years ago
1.0.11
5 years ago
1.0.10
5 years ago
1.0.9
5 years ago
1.0.8
5 years ago
1.0.7
5 years ago
1.0.6
5 years ago
1.0.5
5 years ago
1.0.4
5 years ago
1.0.3
5 years ago
1.0.2
5 years ago
1.0.1
5 years ago