{"id":21437882,"url":"https://github.com/devsrv/cachedfetch","last_synced_at":"2025-07-17T14:06:05.960Z","repository":{"id":101178638,"uuid":"323045388","full_name":"devsrv/cachedfetch","owner":"devsrv","description":"the fetch api with the ability to cache response ","archived":false,"fork":false,"pushed_at":"2020-12-23T15:29:41.000Z","size":58,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-16T23:42:44.770Z","etag":null,"topics":["fetch","javascript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devsrv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-12-20T10:27:11.000Z","updated_at":"2024-06-28T13:46:19.000Z","dependencies_parsed_at":"2023-09-18T15:01:09.312Z","dependency_job_id":null,"html_url":"https://github.com/devsrv/cachedfetch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/devsrv/cachedfetch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devsrv%2Fcachedfetch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devsrv%2Fcachedfetch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devsrv%2Fcachedfetch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devsrv%2Fcachedfetch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devsrv","download_url":"https://codeload.github.com/devsrv/cachedfetch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devsrv%2Fcachedfetch/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265614251,"owners_count":23798414,"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":["fetch","javascript"],"created_at":"2024-11-23T00:30:04.802Z","updated_at":"2025-07-17T14:06:05.954Z","avatar_url":"https://github.com/devsrv.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cachedFetch\n\u003e A micro utility built around the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) that allows caching network query results. \n\u003e Support *`localStorage`, `sessionStorage`, `AsyncStorage` (React Native)*\n\n## 📥 Installation\n\nsimply include the [adapter.min.js](https://github.com/devsrv/cachedfetch/blob/master/adapter.min.js) file in your project\n\n\n## 🧪 The config file :\n\n```javascript\nconst config = {\n    mode: 'block',\t//support block | allow\n    matchIn: [\n        'https://jsonplaceholder.typicode.com/posts/1'\n    ],\n    endsWith: [\n        '?postId=1',\n        // '/posts'\n    ],\n    defaultTTL: '5 day',\t// day | hour | minute | second\n    driver: 'sessionStorage', // localStorage (default) | sessionStorage | AsyncStorage\n    disk: undefined\t\t\t// undefined | AsyncStorage\n};\n```\n\n## For `React Native`\n```javascript\nimport AsyncStorage from '@react-native-async-storage/async-storage';\n\nconst config = {\n    mode: 'block',\n    .\n    .\n    driver: 'AsyncStorage',\n    disk: AsyncStorage\n};\n```\n\n### Initialization with common headers \u0026 config\n\n```javascript\nconst headers = new Headers();\nheaders.append('Accept', 'application/json');\nheaders.append('Content-Type', 'application/json');\nheaders.append('X-Requested-With', 'XMLHttpRequest');\n// headers.append('X-CSRF-Token', document.querySelector('meta[name=\"csrf-token\"]').content);\n```\n\n```javascript\nimport _initCachedFetch from './the-minified-adapter-file-above';\t// alternative to including the bundled js as external script\n\nconst cachedFetch = _initCachedFetch(config, headers);\n```\n\n### EXAMPLES\n\n____\n\n__1. GET request with override cache mode__\n\n```javascript\ncachedFetch('fetch_posts', 'https://jsonplaceholder.typicode.com/posts', {\n    'keep-cache' : true, // override mode\n    cacheTTL: '1 minute'\n    // any additional options goes here\n})\n.then(r =\u003e r.json())\n.then(res =\u003e console.log('result', res));\n```\n\n__2. POST request (using global cache config)__\n\n```javascript\ncachedFetch('add_user', 'https://reqres.in/api/users', {\n    method: 'POST',\n    body: JSON.stringify({name: 'sourav', job: 'engineer'}),\n})\n.then(r =\u003e r.json())\n.then(res =\u003e console.log('result', res));\n```\n\n__3. when content-type text/*__\n\n```javascript\ncachedFetch('fetch_posts', 'https://httpbin.org/html', {\n    'keep-cache' : true,\n    cacheTTL: '1 minute'\n})\n.then(r =\u003e r.text())\n.then(res =\u003e console.log('result', res));\n```\n\n\n## 👋🏼 Say Hi! \nLeave a ⭐ if you find this package useful 👍🏼,\n\nalso don't forget to let me know in [Twitter](https://twitter.com/srvrksh)  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevsrv%2Fcachedfetch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevsrv%2Fcachedfetch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevsrv%2Fcachedfetch/lists"}