{"id":19901109,"url":"https://github.com/chanceyu/axios-storage","last_synced_at":"2025-05-02T23:31:26.392Z","repository":{"id":98815635,"uuid":"147933937","full_name":"ChanceYu/axios-storage","owner":"ChanceYu","description":":floppy_disk: An ajax cache package for axios","archived":false,"fork":false,"pushed_at":"2018-10-20T06:00:23.000Z","size":64,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-03T20:05:43.023Z","etag":null,"topics":["axios","cache","storage"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ChanceYu.png","metadata":{"files":{"readme":"README-zh.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-08T13:03:53.000Z","updated_at":"2022-11-11T01:09:32.000Z","dependencies_parsed_at":"2023-05-02T07:24:43.779Z","dependency_job_id":null,"html_url":"https://github.com/ChanceYu/axios-storage","commit_stats":{"total_commits":18,"total_committers":2,"mean_commits":9.0,"dds":0.2222222222222222,"last_synced_commit":"791a70339a1c1735cdfb8d0a840ad80a294fb741"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChanceYu%2Faxios-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChanceYu%2Faxios-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChanceYu%2Faxios-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChanceYu%2Faxios-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChanceYu","download_url":"https://codeload.github.com/ChanceYu/axios-storage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224341314,"owners_count":17295271,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["axios","cache","storage"],"created_at":"2024-11-12T20:14:07.486Z","updated_at":"2024-11-12T20:14:08.031Z","avatar_url":"https://github.com/ChanceYu.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# axios-storage\n\n[![NPM][img-npm]][url-npm]\n\n[![Language][img-javascript]][url-github]\n[![License][img-mit]][url-mit]\n\n[English](./README.md) | [中文](./README-zh.md)\n\naxios 库请求缓存插件\n\n## 特点\n\n- 支持 `localStorage`、`sessionStorage`、`memory` 三种模式\n- 支持每个请求单独配置\n- 如果本次请求参数和上次的不一致，那么不使用缓存，而是会重新发起请求\n\n\n## 安装\n使用 npm:\n\n```bash\nnpm install axios-storage --save\n```\n\n使用 cdn:\n\n```html\n\u003cscript src=\"https://unpkg.com/axios-storage/dist/axios-storage.js\"\u003e\u003c/script\u003e\n```\n\n\n## 使用\n\n```javascript\nimport axios from 'axios';\nimport AxiosStorage from 'axios-storage';\n\n// 全局配置\nAxiosStorage.config({\n    storagePrefix: 'axios-storage',\n    storageMode: 'sessionStorage',\n    maxAge: 120 * 60 * 1000\n});\n\nconst api = axios.create({\n    adapter: AxiosStorage.adapter\n});\n\napi({\n    method: 'get',\n    url: '/data',\n    cacheConfig: {\n        maxAge: 60 * 60 * 1000,\n        storageMode: 'sessionStorage'\n    }\n})\n.then(function(res){\n    console.log(res);\n})\n\napi({\n    method: 'get',\n    url: '/data/other',\n    cacheConfig: {\n        maxAge: 60 * 60 * 1000,\n        storageMode: 'localStorage'\n    }\n})\n.then(function(res){\n    console.log(res);\n})\n\n// 使用全局配置\napi({\n    method: 'get',\n    url: '/data/other',\n    cacheConfig: true\n})\n.then(function(res){\n    console.log(res);\n})\n```\n\n\n\u003ca name=\"AxiosStorage\"\u003e\u003c/a\u003e\n\n## API\n\n* [AxiosStorage](#AxiosStorage)\n    * [.config(options)](#AxiosStorage.config)\n    * [.adapter()](#AxiosStorage.adapter)\n    * [.getCache(options)](#AxiosStorage.getCache) ⇒ \u003ccode\u003eobject\u003c/code\u003e\n\n\u003ca name=\"AxiosStorage.config\"\u003e\u003c/a\u003e\n\n### AxiosStorage.config(options)\n全局配置参数，\n查看所有参数[详情](http://www.pseudobry.com/CacheFactory/latest/Cache.html)\n\n\n| 参数 | 类型 | 默认值 | 描述 |\n| --- | --- | --- | --- |\n| options | \u003ccode\u003eobject\u003c/code\u003e |  |  |\n| [options.storagePrefix] | \u003ccode\u003estring\u003c/code\u003e | \u003ccode\u003e\u0026quot;axios-storage\u0026quot;\u003c/code\u003e | storage 缓存前缀 |\n| [options.storageMode] | \u003ccode\u003estring\u003c/code\u003e | \u003ccode\u003e\u0026quot;sessionStorage\u0026quot;\u003c/code\u003e | 缓存模式，支持 `localStorage`、`sessionStorage`、`memory` |\n| [options.deleteOnExpire] | \u003ccode\u003estring\u003c/code\u003e | \u003ccode\u003e\u0026quot;aggressive\u0026quot;\u003c/code\u003e | 如何处理过期的缓存，默认过期就会删除 |\n\n**示例**  \n```js\nimport axios from 'axios';\nimport AxiosStorage from 'axios-storage';\n\nAxiosStorage.config({\n  storagePrefix: 'axios-storage-example:',\n  storageMode: 'sessionStorage'\n});\n```\n\u003ca name=\"AxiosStorage.adapter\"\u003e\u003c/a\u003e\n\n### AxiosStorage.adapter()\n适配器\n\n**示例**  \n```js\nimport axios from 'axios';\nimport AxiosStorage from 'axios-storage';\n\nconst api = axios.create({\n  adapter: AxiosStorage.adapter\n});\n\napi.get(...)\napi.post(...)\n```\n\u003ca name=\"AxiosStorage.getCache\"\u003e\u003c/a\u003e\n\n### AxiosStorage.getCache(options) ⇒ \u003ccode\u003eobject\u003c/code\u003e\n缓存对象\n\n**Returns**: \u003ccode\u003eobject\u003c/code\u003e - Cache，查看详情 [Cache](http://www.pseudobry.com/CacheFactory/latest/Cache.html)  \n\n| 参数 | 类型 | 默认值 | 描述 |\n| --- | --- | --- | --- |\n| options | \u003ccode\u003eobject\u003c/code\u003e \\| \u003ccode\u003estring\u003c/code\u003e |  |  |\n| [options.storageMode] | \u003ccode\u003estring\u003c/code\u003e | \u003ccode\u003e\u0026quot;sessionStorage\u0026quot;\u003c/code\u003e | 缓存模式 |\n\n**示例**  \n```js\nlet oCache = AxiosStorage.getCache('localStorage');\n\noCache.put('foo', 'bar');\noCache.get('foo'); // \"bar\"\n...\n\n// 配置cacheConfig\napi({\n  method: 'GET',\n  url: '/data/other',\n  cacheConfig: {\n    maxAge: 60 * 60 * 1000,\n    storageMode: 'localStorage'\n  }\n})\n.then((res) =\u003e {\n   console.log(res)\n})\n\n// 获取请求的缓存\nlet res = oCache.get('GET./data/other') // `res` 和上面的 `res` 结果一样\n\noCache.get('[method].[url]') // `method` 是大写, GET、POST 等\n```\n\n\n\n## 示例\n[example](./example)\n\n```bash\ncd example \u0026\u0026 npm install\n```\n```bash\nnode app.js\n```\n安装和启动之后，浏览器打开 [http://localhost:3000/](http://localhost:3000/) 就可以查看\n\n\n## 感谢\n\n[cachefactory](https://www.npmjs.com/package/cachefactory)\n\n\n## 协议\n\n[![license][img-mit]][url-mit]\n\n\n[url-github]: https://github.com/ChanceYu/axios-storage\n[url-npm]: https://www.npmjs.com/package/axios-storage\n[url-mit]: https://opensource.org/licenses/mit-license.php\n\n[img-npm]: https://nodei.co/npm/axios-storage.png?compact=true\n[img-javascript]: https://img.shields.io/badge/language-JavaScript-brightgreen.svg\n[img-mit]: https://img.shields.io/badge/license-MIT-blue.svg\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchanceyu%2Faxios-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchanceyu%2Faxios-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchanceyu%2Faxios-storage/lists"}