{"id":21920399,"url":"https://github.com/danidelgadoz/ngx-request-cache","last_synced_at":"2025-07-12T02:04:11.386Z","repository":{"id":40667781,"uuid":"255192912","full_name":"danidelgadoz/ngx-request-cache","owner":"danidelgadoz","description":"Cache for HTTP requests with Angular HttpClient","archived":false,"fork":false,"pushed_at":"2023-03-07T17:56:21.000Z","size":1385,"stargazers_count":4,"open_issues_count":9,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-24T00:51:49.315Z","etag":null,"topics":["angular","cache","http-client","request","typescript"],"latest_commit_sha":null,"homepage":"https://ngx-request-cache.web.app/","language":"TypeScript","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/danidelgadoz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-04-13T00:02:32.000Z","updated_at":"2022-04-11T02:53:48.000Z","dependencies_parsed_at":"2024-11-28T20:14:34.318Z","dependency_job_id":"e049e632-c05e-4c33-b0c4-f588dd3e12fe","html_url":"https://github.com/danidelgadoz/ngx-request-cache","commit_stats":{"total_commits":25,"total_committers":1,"mean_commits":25.0,"dds":0.0,"last_synced_commit":"7cc55f5d1ce5cff8b687c3d28870910baa7c4b81"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/danidelgadoz/ngx-request-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danidelgadoz%2Fngx-request-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danidelgadoz%2Fngx-request-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danidelgadoz%2Fngx-request-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danidelgadoz%2Fngx-request-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danidelgadoz","download_url":"https://codeload.github.com/danidelgadoz/ngx-request-cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danidelgadoz%2Fngx-request-cache/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264923366,"owners_count":23683735,"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":["angular","cache","http-client","request","typescript"],"created_at":"2024-11-28T20:14:30.620Z","updated_at":"2025-07-12T02:04:11.341Z","avatar_url":"https://github.com/danidelgadoz.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NgxRequestCache\n\nCache for HTTP requests with Angular `HttpClient`.\n\n**Common usages:**\n* Avoid hitting server to fetch same data when service is invoked serially or in parallel.\n* Create offline application.\n\n*Library relies on ensure requests go through Angular `HttpInterceptor` (default behavior).*\n\n## Demo\nCheck [live demo](https://ngx-request-cache.web.app) on your navigator **monitoring devtool's network** and take a look to the source on [StackBlitz](https://stackblitz.com/edit/ngx-request-cache-demo).\n\n## Installation\n\n```bash\nnpm i ngx-request-cache\n```\n## Usage\n\n* **Setup root module:**\n\n```javascript\nimport { NgxRequestCacheModule } from 'ngx-request-cache';\n\n@NgModule({\n  imports: [ NgxRequestCacheModule ]\n})\n```\n\nBy default, persistence is on memory. To switch to sessionStorage or localStorage, [review here](#other-setups).\n\n* **Cache an API:**\n\n```javascript\nimport { HttpClient, HttpHeaders } from '@angular/common/http';\nimport { RequestCacheHeader } from 'ngx-request-cache';\n\n@Injectable()\nexport class DataService {\n  constructor(private http: HttpClient) { }\n\n  getData(): Observable\u003cany\u003e {\n    let headers = new HttpHeaders();\n    headers = headers.append(RequestCacheHeader.Cachable, '');\n\n    return this.http.get(`URL`, { headers });\n  }\n}\n```\nLibrary's headers are removed before sending the request to the server.\n\n* **Clear cache:**\n\n```javascript\nimport { RequestCacheService } from 'ngx-request-cache';\n\nexport class DataService {\n  constructor(private requestCacheService: RequestCacheService) {\n    this.requestCacheService.clear(); // All data stored.\n  }\n}\n```\n\n## Other setups\n\nCache store with persistence into \u003ccode\u003esessionStorage\u003c/code\u003e:\n\n```javascript\n@NgModule({\n  imports: [ \n    NgxRequestCacheModule.forRoot({ store: 'sessionStorage' })\n  ]\n})\n```\n\nCache store with persistence into \u003ccode\u003elocalStorage\u003c/code\u003e:\n\n```javascript\n@NgModule({\n  imports: [ \n    NgxRequestCacheModule.forRoot({ store: 'localStorage' })\n  ]\n})\n```\n\n# How it works?\n* If a request has `Cachable` header, then a cached response is returned. \u003cins\u003eIf there isn't a cached response\u003c/ins\u003e, request is send to server and when the operation has completed the response is cached.\n* A response is stored associating a unique ID generated from request method, url with params and body.\n* \u003cins\u003eToo Many Requests\u003c/ins\u003e prevented: If 10 identical request are made at the same time, the first hits the server and the other 9 keep waiting for it's response to emit the response wherever they were invoked.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanidelgadoz%2Fngx-request-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanidelgadoz%2Fngx-request-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanidelgadoz%2Fngx-request-cache/lists"}