Registry / storage / axios-cache-adapter-util

axios-cache-adapter-util

JSON →
library1.0.57jsnpmunverified

A utility for exporting and importing axios-cache-adapter cache stores to/from JSON files, enabling persistent cache across restarts or sharing between processes. Current version 1.0.57, with weekly releases. Key differentiators: built-in process exit hook integration, TypeScript support, and direct filesystem operations via fs-extra. Requires peer dependencies axios (^0.21.1) and axios-cache-adapter (^2.7.3). Commonly used to save API cache to disk and reload on app startup.

npm install axios-cache-adapter-util
INSTALL
IMPORT
SIG · AXIOS-CACHE-ADAPTE
A
axios-cache-adapter-util
storagejavascriptv1.0.57
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

exportCache
import { exportCache } from 'axios-cache-adapter-util'
const exportCache = require('axios-cache-adapter-util').exportCache
ESM-only; TypeScript types included.
importCache
import { importCache } from 'axios-cache-adapter-util'
import importCache from 'axios-cache-adapter-util'
Named export, not default.
processExitHook
import { processExitHook } from 'axios-cache-adapter-util'
import { processExitHook } from 'axios-cache-adapter'
Separate utility; not part of axios-cache-adapter.

Initialize cache adapter, load existing cache from JSON file, make a request, then save updated cache back to file.

import Axios from 'axios'; import { setupCache } from 'axios-cache-adapter'; import { exportCache, importCache } from 'axios-cache-adapter-util'; import fs from 'fs-extra'; const cache = setupCache({ maxAge: 15 * 60 * 1000 }); const cacheFile = './cache.json'; // Load cache from file fs.readJson(cacheFile).then(async (json) => { await importCache(cache.store, json); }).catch(() => {}); // Use axios with cache const axios = Axios.create({ adapter: cache.adapter }); await axios.get('https://api.example.com/data'); // Export cache to file await exportCache(cache.store, (json) => { fs.outputJsonSync(cacheFile, json, { spaces: 2 }); console.log('Cache saved'); });
Debug
Known issues
breakingVersion 1.0.0 dropped support for axios <0.21.0 and axios-cache-adapter <2.7.0.
fix
Upgrade axios to ^0.21.1 and axios-cache-adapter to ^2.7.3.
affects: <1.0.0
gotchaexportCache expects a callback, not a direct file path. The callback must handle serialization.
fix
Pass a callback function to exportCache that receives JSON and writes it to file.
affects: >=1.0.0
gotchaimportCache returns a Promise; must be awaited to ensure cache is fully loaded before making requests.
fix
Use await or .then() when calling importCache.
affects: >=1.0.0
deprecatedThe 'processExitHook' function may be removed in future versions; prefer manual save triggers.
fix
Call exportCache explicitly instead of relying on exit hook.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'axios-cache-adapter-util'
Package not installed correctly or missing from node_modules.
fix
Run npm install axios-cache-adapter-util or yarn add axios-cache-adapter-util.
TypeError: cache.store.length is not a function
cache.store is not the expected object; possibly wrong version of axios-cache-adapter.
fix
Ensure axios-cache-adapter version 2.7.3 or newer is installed.
exportCache is not a function
Named import incorrectly or mix of ESM/CJS.
fix
Use import { exportCache } from 'axios-cache-adapter-util' (ESM) or const { exportCache } = require('axios-cache-adapter-util') (CJS) consistently.
Upgrade
Version history
1.0.57latest on npm
Audit
Dependencies
axiosrequiredPeer dependency; required for creating axios instances with cache adapter.
axios-cache-adapterrequiredPeer dependency; provides the cache store and setupCache function.
fs-extraoptionalRuntime dependency; used for reading/writing JSON cache files.
Agent activity
46 hits · last 30 days
node
40
OpenAI (training)
1
Resources
axios-cache-adapter-util — npm install axios-cache-adapter-util · libregistry