{"id":16347313,"url":"https://github.com/imbhargav5/fetch-unless-cached","last_synced_at":"2025-10-26T02:30:19.568Z","repository":{"id":57234765,"uuid":"122954251","full_name":"imbhargav5/fetch-unless-cached","owner":"imbhargav5","description":"Store fetch responses in localStorage with expire timers! And fetch when idle and update cache in the background","archived":false,"fork":false,"pushed_at":"2018-04-02T14:33:14.000Z","size":219,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-08T23:32:44.989Z","etag":null,"topics":["isomorphic-fetch","json","lscache"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/fetch-unless-cached","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/imbhargav5.png","metadata":{"files":{"readme":"README.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}},"created_at":"2018-02-26T10:34:07.000Z","updated_at":"2020-12-23T20:29:57.000Z","dependencies_parsed_at":"2022-09-15T06:51:19.045Z","dependency_job_id":null,"html_url":"https://github.com/imbhargav5/fetch-unless-cached","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imbhargav5%2Ffetch-unless-cached","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imbhargav5%2Ffetch-unless-cached/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imbhargav5%2Ffetch-unless-cached/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imbhargav5%2Ffetch-unless-cached/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imbhargav5","download_url":"https://codeload.github.com/imbhargav5/fetch-unless-cached/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238241444,"owners_count":19439767,"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":["isomorphic-fetch","json","lscache"],"created_at":"2024-10-11T00:41:20.214Z","updated_at":"2025-10-26T02:30:19.218Z","avatar_url":"https://github.com/imbhargav5.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fetch-unless-cached\n\nStore fetch JSON responses in localStorage with expire timers! And fetch only if the timer has expired.\n\n\u003chr/\u003e\n\n[![](https://nodei.co/npm/fetch-unless-cached.png?compact=true)](https://nodei.co/npm/fetch-unless-cached/)\n\n[![npm](https://img.shields.io/npm/dm/fetch-unless-cached.svg?style=for-the-badge)](https://www.npmjs.com/package/fetch-unless-cached)\n[![npm](https://img.shields.io/npm/l/fetch-unless-cached.svg?style=for-the-badge)](https://www.npmjs.com/package/fetch-unless-cached)\n\n## What is it really?\n\n* A wrapper on top isomorphic-fetch for JSON responses\n* When data is fetched, it's stored in localStorage with an expire timer\n* When data is reqeusted, it checks in the storage and only fetches if needed, otherwise it resolves the cached data.\n* Optionally, the api call can be made when the browser is idle and the timer is udpated.\n\n## Installation\n\n```shell\nnpm i --save fetch-unless-cached\n```\n\n## Usage\n\n1. Use the inbuilt cached fetch which caches response for 600 minutes.\n\n   ```javascript\n   import cachedFetch from \"fetch-unless-cached\";\n   ```\n\n2. Or create a custom cached fetch function with your own duration\n\n```javascript\nimport {createfetchUnlessCached} from \"fetch-unless-cached\"\n\n/**\n * Create a custom fetch function which caches response for 300 minutes\n */\nconst cachedFetch = createfetchUnlessCached(300)\n\nfunction fetchMyData(){\n  /*\n   * cachedFetch is just isomorphic-fetch but coupled with cache\n   * Do not perform .then(res =\u003e res.json()) as this happens internally\n   *\n   */\n  ...\n  return cachedFetch('myapi.com').then(response =\u003e console.log(response))\n}\n```\n\nNote: If you would like to fetch during an idle state you can set the second argument to true.\n\n```javascript\nconst cachedFetch = createfetchUnlessCached(300, true);\n```\n\n### Credits\n\n* [x] isomorphic-fetch - Fetch api for node and browser\n* [x] lscache - localStorage caching with timers\n\n## Caveats\n\n* [x] Works only with JSON responses\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimbhargav5%2Ffetch-unless-cached","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimbhargav5%2Ffetch-unless-cached","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimbhargav5%2Ffetch-unless-cached/lists"}