{"id":44354,"library":"axios-cache-adapter-util","title":"axios-cache-adapter-util","description":"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.","status":"active","version":"1.0.57","language":"javascript","source_language":"en","source_url":"https://github.com/bluelovers/ws-rest","tags":["javascript","axios","axios-cache-adapter","cache","export","fs","import","json","request","typescript"],"install":[{"cmd":"npm install axios-cache-adapter-util","lang":"bash","label":"npm"},{"cmd":"yarn add axios-cache-adapter-util","lang":"bash","label":"yarn"},{"cmd":"pnpm add axios-cache-adapter-util","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; required for creating axios instances with cache adapter.","package":"axios","optional":false},{"reason":"Peer dependency; provides the cache store and setupCache function.","package":"axios-cache-adapter","optional":false},{"reason":"Runtime dependency; used for reading/writing JSON cache files.","package":"fs-extra","optional":true}],"imports":[{"note":"ESM-only; TypeScript types included.","wrong":"const exportCache = require('axios-cache-adapter-util').exportCache","symbol":"exportCache","correct":"import { exportCache } from 'axios-cache-adapter-util'"},{"note":"Named export, not default.","wrong":"import importCache from 'axios-cache-adapter-util'","symbol":"importCache","correct":"import { importCache } from 'axios-cache-adapter-util'"},{"note":"Separate utility; not part of axios-cache-adapter.","wrong":"import { processExitHook } from 'axios-cache-adapter'","symbol":"processExitHook","correct":"import { processExitHook } from 'axios-cache-adapter-util'"}],"quickstart":{"code":"import Axios from 'axios';\nimport { setupCache } from 'axios-cache-adapter';\nimport { exportCache, importCache } from 'axios-cache-adapter-util';\nimport fs from 'fs-extra';\n\nconst cache = setupCache({ maxAge: 15 * 60 * 1000 });\nconst cacheFile = './cache.json';\n\n// Load cache from file\nfs.readJson(cacheFile).then(async (json) => {\n  await importCache(cache.store, json);\n}).catch(() => {});\n\n// Use axios with cache\nconst axios = Axios.create({ adapter: cache.adapter });\nawait axios.get('https://api.example.com/data');\n\n// Export cache to file\nawait exportCache(cache.store, (json) => {\n  fs.outputJsonSync(cacheFile, json, { spaces: 2 });\n  console.log('Cache saved');\n});","lang":"typescript","description":"Initialize cache adapter, load existing cache from JSON file, make a request, then save updated cache back to file."},"warnings":[{"fix":"Upgrade axios to ^0.21.1 and axios-cache-adapter to ^2.7.3.","message":"Version 1.0.0 dropped support for axios <0.21.0 and axios-cache-adapter <2.7.0.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Pass a callback function to exportCache that receives JSON and writes it to file.","message":"exportCache expects a callback, not a direct file path. The callback must handle serialization.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use await or .then() when calling importCache.","message":"importCache returns a Promise; must be awaited to ensure cache is fully loaded before making requests.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Call exportCache explicitly instead of relying on exit hook.","message":"The 'processExitHook' function may be removed in future versions; prefer manual save triggers.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'0.21.1':59 '1.0.57':32 '2.7.3':65 'across':24 'adapt':4,15,64,84 'api':70 'app':77 'axio':2,13,58,62,80,82 'axios-cache-adapt':12,61,81 'axios-cache-adapter-util':1 'built':39 'built-in':38 'cach':3,14,16,23,63,71,83,85 'common':66 'current':30 'depend':57 'differenti':37 'direct':48 'disk':73 'enabl':21 'exit':42 'export':9,86 'extra':54 'file':20 'filesystem':49 'fs':53,87 'fs-extra':52 'hook':43 'import':11,88 'integr':44 'javascript':79 'json':19,89 'key':36 'oper':50 'peer':56 'persist':22 'process':29,41 'releas':35 'reload':75 'request':90 'requir':55 'restart':25 'save':69 'share':27 'startup':78 'store':17 'support':46 'to/from':18 'typescript':45,91 'use':67 'util':5,7 'version':31 'via':51 'week':34","created_at":"2026-06-07T12:49:43.789497+00:00","updated_at":"2026-06-07T12:49:43.789497+00:00","problems":[{"fix":"Run npm install axios-cache-adapter-util or yarn add axios-cache-adapter-util.","cause":"Package not installed correctly or missing from node_modules.","error":"Cannot find module 'axios-cache-adapter-util'"},{"fix":"Ensure axios-cache-adapter version 2.7.3 or newer is installed.","cause":"cache.store is not the expected object; possibly wrong version of axios-cache-adapter.","error":"TypeError: cache.store.length is not a function"},{"fix":"Use import { exportCache } from 'axios-cache-adapter-util' (ESM) or const { exportCache } = require('axios-cache-adapter-util') (CJS) consistently.","cause":"Named import incorrectly or mix of ESM/CJS.","error":"exportCache is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/bluelovers/ws-rest#readme","github":"https://github.com/bluelovers/ws-rest","docs":null,"changelog":null,"pypi":null,"npm":"axios-cache-adapter-util","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}