Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

axios-cache-adapter-util

bluelovers217ISC1.0.57TypeScript support: included

axios-cache-adapter export/import json for save/load file

axios, axios-cache-adapter, cache, export, fs, import, json, request, xhr

readme

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();
    }

})();

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

1.0.57 (2021-08-12)

✨ Features

  • deps: update axios to ^0.21.1, maybe will has unknown bug (c0801ff)

BREAKING CHANGE

  • deps: update axios to ^0.21.1, maybe will has unknown bug

1.0.56 (2021-07-28)

Note: Version bump only for package axios-cache-adapter-util

1.0.55 (2021-07-27)

🔖 Miscellaneous

1.0.54 (2021-07-20)

🐛 Bug Fixes

  • use defaultAxiosCacheAdapterKeyFixed (8df465d)

🛠 Build System

  • { prepublishOnly => preversion } (066a436)

♻️ Chores

1.0.53 (2021-07-10)

Note: Version bump only for package axios-cache-adapter-util

1.0.52 (2021-07-05)

Note: Version bump only for package axios-cache-adapter-util

1.0.51 (2021-07-04)

Note: Version bump only for package axios-cache-adapter-util

1.0.50 (2021-07-03)

♻️ Chores

1.0.49 (2021-05-28)

✨ Features

📦 Code Refactoring

  • update fs import add use freeGC (7de5939)

♻️ Chores

1.0.48 (2021-02-04)

🔖 Miscellaneous

1.0.47 (2021-02-03)

♻️ Chores

1.0.46 (2020-12-04)

Note: Version bump only for package axios-cache-adapter-util

1.0.45 (2020-09-05)

♻️ Chores

1.0.44 (2020-09-03)

♻️ Chores

1.0.43 (2020-07-31)

🛠 Build System

  • add build file into git (caf8ba5)

1.0.42 (2020-07-27)

♻️ Chores

1.0.41 (2020-07-20)

🔖 Miscellaneous

1.0.40 (2020-07-20)

♻️ Chores

1.0.39 (2020-06-16)

♻️ Chores

✨ Features

1.0.38 (2020-06-05)

Note: Version bump only for package axios-cache-adapter-util

1.0.37 (2020-05-08)

Note: Version bump only for package axios-cache-adapter-util

1.0.36 (2020-05-08)

Note: Version bump only for package axios-cache-adapter-util

1.0.35 (2020-04-29)

Note: Version bump only for package axios-cache-adapter-util

1.0.34 (2020-04-10)

Note: Version bump only for package axios-cache-adapter-util

1.0.33 (2020-04-10)

Note: Version bump only for package axios-cache-adapter-util