p3x-angular-http-cache-interceptor 2026.4.112 → 2026.4.117

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
 
9
- # 🔥 Cache every request in Angular, not only the GET, but all methods of this interceptor, and allows you to interact with the interceptor via specific headers and modify the request, and these specific headers will be not included in the final request v2026.4.112
9
+ # 🔥 Cache every request in Angular, not only the GET, but all methods of this interceptor, and allows you to interact with the interceptor via specific headers and modify the request, and these specific headers will be not included in the final request v2026.4.117
10
10
 
11
11
 
12
12
 
@@ -22,7 +22,7 @@
22
22
  ### 🛠️ Built on NodeJs version
23
23
 
24
24
  ```txt
25
- v24.14.1
25
+ v24.16.0
26
26
  ```
27
27
 
28
28
 
@@ -31,7 +31,7 @@ v24.14.1
31
31
  # 📦 Built on Angular
32
32
 
33
33
  ```text
34
- 21.2.10
34
+ 22.0.0
35
35
  ```
36
36
 
37
37
 
@@ -257,7 +257,7 @@ All my domains, including [patrikx3.com](https://patrikx3.com), [corifeus.eu](ht
257
257
  **🚨 Important Changes:** Any breaking changes are prominently noted in the readme to keep you informed.
258
258
 
259
259
 
260
- [**P3X-ANGULAR-HTTP-CACHE-INTERCEPTOR**](https://corifeus.com/angular-http-cache-interceptor) Build v2026.4.112
260
+ [**P3X-ANGULAR-HTTP-CACHE-INTERCEPTOR**](https://corifeus.com/angular-http-cache-interceptor) Build v2026.4.117
261
261
 
262
262
  [![NPM](https://img.shields.io/npm/v/p3x-angular-http-cache-interceptor.svg)](https://www.npmjs.com/package/p3x-angular-http-cache-interceptor) [![Donate for PatrikX3 / P3X](https://img.shields.io/badge/Donate-PatrikX3-003087.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QZVM4V6HVZJW6) [![Contact Corifeus / P3X](https://img.shields.io/badge/Contact-P3X-ff9900.svg)](https://www.patrikx3.com/en/front/contact) [![Like Corifeus @ Facebook](https://img.shields.io/badge/LIKE-Corifeus-3b5998.svg)](https://www.facebook.com/corifeus.software)
263
263
 
@@ -95,10 +95,10 @@ class HttpCacheInterceptorInterceptor {
95
95
  intercept(httpRequest, next) {
96
96
  return handle(httpRequest, (req) => next.handle(req), this.httpCacheConfig, this.cachedData);
97
97
  }
98
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: HttpCacheInterceptorInterceptor, deps: [{ token: P3X_HTTP_CACHE_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
99
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: HttpCacheInterceptorInterceptor }); }
98
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.0", ngImport: i0, type: HttpCacheInterceptorInterceptor, deps: [{ token: P3X_HTTP_CACHE_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
99
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.0", ngImport: i0, type: HttpCacheInterceptorInterceptor }); }
100
100
  }
101
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: HttpCacheInterceptorInterceptor, decorators: [{
101
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.0", ngImport: i0, type: HttpCacheInterceptorInterceptor, decorators: [{
102
102
  type: Injectable
103
103
  }], ctorParameters: () => [{ type: undefined, decorators: [{
104
104
  type: Inject,
@@ -142,9 +142,9 @@ class P3XHttpCacheInterceptorModule {
142
142
  providers,
143
143
  };
144
144
  }
145
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: P3XHttpCacheInterceptorModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
146
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.10", ngImport: i0, type: P3XHttpCacheInterceptorModule }); }
147
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: P3XHttpCacheInterceptorModule, providers: [
145
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.0", ngImport: i0, type: P3XHttpCacheInterceptorModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
146
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "22.0.0", ngImport: i0, type: P3XHttpCacheInterceptorModule }); }
147
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "22.0.0", ngImport: i0, type: P3XHttpCacheInterceptorModule, providers: [
148
148
  {
149
149
  provide: HTTP_INTERCEPTORS,
150
150
  useClass: HttpCacheInterceptorInterceptor,
@@ -152,7 +152,7 @@ class P3XHttpCacheInterceptorModule {
152
152
  },
153
153
  ] }); }
154
154
  }
155
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: P3XHttpCacheInterceptorModule, decorators: [{
155
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.0", ngImport: i0, type: P3XHttpCacheInterceptorModule, decorators: [{
156
156
  type: NgModule,
157
157
  args: [{
158
158
  providers: [
@@ -1 +1 @@
1
- {"version":3,"file":"p3x-angular-http-cache-interceptor.mjs","sources":["../../../projects/angular-http-cache-interceptor/src/lib/caching-headers.enum.ts","../../../projects/angular-http-cache-interceptor/src/lib/caching-store.enum.ts","../../../projects/angular-http-cache-interceptor/src/lib/http-cache-config.token.ts","../../../projects/angular-http-cache-interceptor/src/lib/http-cache-interceptor.interceptor.ts","../../../projects/angular-http-cache-interceptor/src/lib/http-cache-interceptor.module.ts","../../../projects/angular-http-cache-interceptor/src/public-api.ts","../../../projects/angular-http-cache-interceptor/src/p3x-angular-http-cache-interceptor.ts"],"sourcesContent":["// cache headers has to have a x- prefix\nexport enum CachingHeaders {\n NoCache = \"x-p3x-no-cache\",\n Cache = \"x-p3x-cache\",\n}\n","// cache headers has to have a x- prefix\nexport enum CachingStore {\n Global,\n PerModule\n}\n","import { InjectionToken } from \"@angular/core\";\nimport { HttpCacheConfig } from \"./http-cache-config\";\n\nexport const P3X_HTTP_CACHE_CONFIG = new InjectionToken<HttpCacheConfig>(\n 'P3X_HTTP_CACHE_CONFIG'\n)\n","import { inject, Injectable, Optional, Inject } from '@angular/core';\nimport {\n HttpEvent,\n HttpHandler,\n HttpInterceptor,\n HttpInterceptorFn,\n HttpRequest,\n HttpResponse,\n} from '@angular/common/http';\nimport { Observable, of } from 'rxjs';\nimport { tap } from 'rxjs/operators';\n\nimport hash from 'object-hash';\n\nimport { CachingHeaders } from './caching-headers.enum';\nimport { CachingStore } from './caching-store.enum';\nimport { P3X_HTTP_CACHE_CONFIG } from './http-cache-config.token';\nimport { HttpCacheConfig } from './http-cache-config';\n\nconst hashOptions = {\n algorithm: 'md5',\n encoding: 'hex',\n} as const;\n\nconst globalCache = new Map<string, HttpResponse<any>>();\n\nconst DEFAULT_CONFIG: HttpCacheConfig = {\n behavior: CachingHeaders.Cache,\n store: CachingStore.Global,\n};\n\nfunction httpToKey(httpRequest: HttpRequest<any>): string {\n const body = JSON.parse(JSON.stringify(httpRequest.body));\n return (\n httpRequest.method +\n '@' + httpRequest.urlWithParams +\n '@' + hash(httpRequest.params, hashOptions) +\n '@' + hash(body, hashOptions)\n );\n}\n\nfunction handle(\n httpRequest: HttpRequest<unknown>,\n next: (req: HttpRequest<unknown>) => Observable<HttpEvent<unknown>>,\n config: HttpCacheConfig,\n perInstanceCache: Map<string, HttpResponse<any>>,\n): Observable<HttpEvent<unknown>> {\n const forcedCache = httpRequest.headers.get(CachingHeaders.Cache) !== null;\n const forcedNoneCache = httpRequest.headers.get(CachingHeaders.NoCache) !== null;\n\n let headers = httpRequest.headers.delete(CachingHeaders.NoCache);\n headers = headers.delete(CachingHeaders.Cache);\n httpRequest = httpRequest.clone({ headers });\n\n if (forcedCache && forcedNoneCache) {\n throw new Error('You cannot use cache and non-cache header at once!');\n }\n\n if (forcedNoneCache || (config.behavior === CachingHeaders.NoCache && !forcedCache)) {\n return next(httpRequest);\n }\n\n if (forcedCache || (config.behavior === CachingHeaders.Cache && !forcedNoneCache)) {\n const store = config.store === CachingStore.Global ? globalCache : perInstanceCache;\n const key = httpToKey(httpRequest);\n const lastResponse = store.get(key);\n if (lastResponse) {\n return of(lastResponse.clone());\n }\n return next(httpRequest).pipe(\n tap((stateEvent) => {\n if (stateEvent instanceof HttpResponse) {\n store.set(key, stateEvent.clone());\n }\n }),\n );\n }\n\n console.error(config);\n console.error(httpRequest.headers);\n throw new Error('There is a configuration in your setup');\n}\n\n/*\n Functional-interceptor path: there is no \"module instance\" to own a\n PerModule cache, so PerModule falls back to this module-level map (one\n per root injector, effectively Global-equivalent). The class-based\n interceptor below still honours true PerModule via its instance field.\n*/\nconst functionalPerInstanceCache = new Map<string, HttpResponse<any>>();\n\n/**\n * Functional interceptor. Use with:\n * `provideHttpClient(withInterceptors([p3xHttpCacheInterceptor]))`\n * or the convenience `provideP3xHttpCacheInterceptor(config)` helper.\n */\nexport const p3xHttpCacheInterceptor: HttpInterceptorFn = (httpRequest, next) => {\n const config = inject(P3X_HTTP_CACHE_CONFIG, { optional: true }) ?? DEFAULT_CONFIG;\n return handle(httpRequest, (req) => next(req), config, functionalPerInstanceCache);\n};\n\n/**\n * Class-based interceptor — legacy shim kept for consumers still registering\n * via `HTTP_INTERCEPTORS` / `P3XHttpCacheInterceptorModule.forRoot(...)`.\n * Prefer `p3xHttpCacheInterceptor` (functional) for new code.\n */\n@Injectable()\nexport class HttpCacheInterceptorInterceptor implements HttpInterceptor {\n private readonly cachedData = new Map<string, HttpResponse<any>>();\n private readonly httpCacheConfig: HttpCacheConfig;\n\n constructor(@Inject(P3X_HTTP_CACHE_CONFIG) @Optional() httpCacheConfigToken: HttpCacheConfig | null) {\n this.httpCacheConfig = httpCacheConfigToken ?? DEFAULT_CONFIG;\n }\n\n intercept(httpRequest: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {\n return handle(httpRequest, (req) => next.handle(req), this.httpCacheConfig, this.cachedData);\n }\n}\n","import {\n EnvironmentProviders,\n makeEnvironmentProviders,\n ModuleWithProviders,\n NgModule,\n Provider,\n} from '@angular/core';\nimport { HTTP_INTERCEPTORS } from '@angular/common/http';\n\nimport { HttpCacheInterceptorInterceptor } from './http-cache-interceptor.interceptor';\nimport { P3X_HTTP_CACHE_CONFIG } from './http-cache-config.token';\nimport { HttpCacheConfig } from './http-cache-config';\n\n/**\n * Standalone / functional-provider helper.\n *\n * Usage in `app.config.ts`:\n * ```ts\n * provideHttpClient(withInterceptors([p3xHttpCacheInterceptor])),\n * provideP3xHttpCacheInterceptor({ behavior: CachingHeaders.Cache, store: CachingStore.Global }),\n * ```\n */\nexport function provideP3xHttpCacheInterceptor(\n httpCacheConfig: HttpCacheConfig,\n): EnvironmentProviders {\n return makeEnvironmentProviders([\n { provide: P3X_HTTP_CACHE_CONFIG, useValue: httpCacheConfig },\n ]);\n}\n\n/**\n * Legacy NgModule — kept intact for consumers that still bootstrap via\n * `@NgModule({ imports: [P3XHttpCacheInterceptorModule.forRoot(...)] })`\n * and register the class interceptor through `HTTP_INTERCEPTORS`.\n *\n * New code should prefer `provideP3xHttpCacheInterceptor()` +\n * `p3xHttpCacheInterceptor` (functional).\n */\n@NgModule({\n providers: [\n {\n provide: HTTP_INTERCEPTORS,\n useClass: HttpCacheInterceptorInterceptor,\n multi: true,\n },\n ],\n})\nexport class P3XHttpCacheInterceptorModule {\n static forRoot(httpCacheConfig: HttpCacheConfig): ModuleWithProviders<P3XHttpCacheInterceptorModule> {\n const providers: Provider[] = [\n {\n provide: P3X_HTTP_CACHE_CONFIG,\n useValue: httpCacheConfig,\n },\n ];\n return {\n ngModule: P3XHttpCacheInterceptorModule,\n providers,\n };\n }\n}\n","/*\n * Public API Surface of angular-http-cache-interceptor\n */\n\nexport * from './lib/http-cache-interceptor.module';\nexport * from './lib/http-cache-interceptor.interceptor';\nexport * from './lib/caching-headers.enum';\nexport * from './lib/http-cache-config';\nexport * from './lib/http-cache-config.token';\nexport * from './lib/caching-store.enum';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;AAAA;IACY;AAAZ,CAAA,UAAY,cAAc,EAAA;AACxB,IAAA,cAAA,CAAA,SAAA,CAAA,GAAA,gBAA0B;AAC1B,IAAA,cAAA,CAAA,OAAA,CAAA,GAAA,aAAqB;AACvB,CAAC,EAHW,cAAc,KAAd,cAAc,GAAA,EAAA,CAAA,CAAA;;ACD1B;IACY;AAAZ,CAAA,UAAY,YAAY,EAAA;AACtB,IAAA,YAAA,CAAA,YAAA,CAAA,QAAA,CAAA,GAAA,CAAA,CAAA,GAAA,QAAM;AACN,IAAA,YAAA,CAAA,YAAA,CAAA,WAAA,CAAA,GAAA,CAAA,CAAA,GAAA,WAAS;AACX,CAAC,EAHW,YAAY,KAAZ,YAAY,GAAA,EAAA,CAAA,CAAA;;MCEX,qBAAqB,GAAG,IAAI,cAAc,CACrD,uBAAuB;;ACezB,MAAM,WAAW,GAAG;AAChB,IAAA,SAAS,EAAE,KAAK;AAChB,IAAA,QAAQ,EAAE,KAAK;CACT;AAEV,MAAM,WAAW,GAAG,IAAI,GAAG,EAA6B;AAExD,MAAM,cAAc,GAAoB;IACpC,QAAQ,EAAE,cAAc,CAAC,KAAK;IAC9B,KAAK,EAAE,YAAY,CAAC,MAAM;CAC7B;AAED,SAAS,SAAS,CAAC,WAA6B,EAAA;AAC5C,IAAA,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACzD,QACI,WAAW,CAAC,MAAM;QAClB,GAAG,GAA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,OAAO,EAAE,iBAAiB;AAC1B,gBAAA,QAAQ,EAAE,+BAA+B;AACzC,gBAAA,KAAK,EAAE,IAAI;AACd,aAAA;AACJ,SAAA,EAAA,CAAA,CAAA;;4FAEQ,6BAA6B,EAAA,UAAA,EAAA,CAAA;kBATzC,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACN,oBAAA,SAAS,EAAE;AACP,wBAAA;AACI,4BAAA,OAAO,EAAE,iBAAiB;AAC1B,4BAAA,QAAQ,EAAE,+BAA+B;AACzC,4BAAA,KAAK,EAAE,IAAI;AACd,yBAAA;AACJ,qBAAA;AACJ,iBAAA;;;AC9CD;;AAEG;;ACFH;;AAEG;;;;"}
1
+ {"version":3,"file":"p3x-angular-http-cache-interceptor.mjs","sources":["../../../projects/angular-http-cache-interceptor/src/lib/caching-headers.enum.ts","../../../projects/angular-http-cache-interceptor/src/lib/caching-store.enum.ts","../../../projects/angular-http-cache-interceptor/src/lib/http-cache-config.token.ts","../../../projects/angular-http-cache-interceptor/src/lib/http-cache-interceptor.interceptor.ts","../../../projects/angular-http-cache-interceptor/src/lib/http-cache-interceptor.module.ts","../../../projects/angular-http-cache-interceptor/src/public-api.ts","../../../projects/angular-http-cache-interceptor/src/p3x-angular-http-cache-interceptor.ts"],"sourcesContent":["// cache headers has to have a x- prefix\nexport enum CachingHeaders {\n NoCache = \"x-p3x-no-cache\",\n Cache = \"x-p3x-cache\",\n}\n","// cache headers has to have a x- prefix\nexport enum CachingStore {\n Global,\n PerModule\n}\n","import { InjectionToken } from \"@angular/core\";\nimport { HttpCacheConfig } from \"./http-cache-config\";\n\nexport const P3X_HTTP_CACHE_CONFIG = new InjectionToken<HttpCacheConfig>(\n 'P3X_HTTP_CACHE_CONFIG'\n)\n","import { inject, Injectable, Optional, Inject } from '@angular/core';\nimport {\n HttpEvent,\n HttpHandler,\n HttpInterceptor,\n HttpInterceptorFn,\n HttpRequest,\n HttpResponse,\n} from '@angular/common/http';\nimport { Observable, of } from 'rxjs';\nimport { tap } from 'rxjs/operators';\n\nimport hash from 'object-hash';\n\nimport { CachingHeaders } from './caching-headers.enum';\nimport { CachingStore } from './caching-store.enum';\nimport { P3X_HTTP_CACHE_CONFIG } from './http-cache-config.token';\nimport { HttpCacheConfig } from './http-cache-config';\n\nconst hashOptions = {\n algorithm: 'md5',\n encoding: 'hex',\n} as const;\n\nconst globalCache = new Map<string, HttpResponse<any>>();\n\nconst DEFAULT_CONFIG: HttpCacheConfig = {\n behavior: CachingHeaders.Cache,\n store: CachingStore.Global,\n};\n\nfunction httpToKey(httpRequest: HttpRequest<any>): string {\n const body = JSON.parse(JSON.stringify(httpRequest.body));\n return (\n httpRequest.method +\n '@' + httpRequest.urlWithParams +\n '@' + hash(httpRequest.params, hashOptions) +\n '@' + hash(body, hashOptions)\n );\n}\n\nfunction handle(\n httpRequest: HttpRequest<unknown>,\n next: (req: HttpRequest<unknown>) => Observable<HttpEvent<unknown>>,\n config: HttpCacheConfig,\n perInstanceCache: Map<string, HttpResponse<any>>,\n): Observable<HttpEvent<unknown>> {\n const forcedCache = httpRequest.headers.get(CachingHeaders.Cache) !== null;\n const forcedNoneCache = httpRequest.headers.get(CachingHeaders.NoCache) !== null;\n\n let headers = httpRequest.headers.delete(CachingHeaders.NoCache);\n headers = headers.delete(CachingHeaders.Cache);\n httpRequest = httpRequest.clone({ headers });\n\n if (forcedCache && forcedNoneCache) {\n throw new Error('You cannot use cache and non-cache header at once!');\n }\n\n if (forcedNoneCache || (config.behavior === CachingHeaders.NoCache && !forcedCache)) {\n return next(httpRequest);\n }\n\n if (forcedCache || (config.behavior === CachingHeaders.Cache && !forcedNoneCache)) {\n const store = config.store === CachingStore.Global ? globalCache : perInstanceCache;\n const key = httpToKey(httpRequest);\n const lastResponse = store.get(key);\n if (lastResponse) {\n return of(lastResponse.clone());\n }\n return next(httpRequest).pipe(\n tap((stateEvent) => {\n if (stateEvent instanceof HttpResponse) {\n store.set(key, stateEvent.clone());\n }\n }),\n );\n }\n\n console.error(config);\n console.error(httpRequest.headers);\n throw new Error('There is a configuration in your setup');\n}\n\n/*\n Functional-interceptor path: there is no \"module instance\" to own a\n PerModule cache, so PerModule falls back to this module-level map (one\n per root injector, effectively Global-equivalent). The class-based\n interceptor below still honours true PerModule via its instance field.\n*/\nconst functionalPerInstanceCache = new Map<string, HttpResponse<any>>();\n\n/**\n * Functional interceptor. Use with:\n * `provideHttpClient(withInterceptors([p3xHttpCacheInterceptor]))`\n * or the convenience `provideP3xHttpCacheInterceptor(config)` helper.\n */\nexport const p3xHttpCacheInterceptor: HttpInterceptorFn = (httpRequest, next) => {\n const config = inject(P3X_HTTP_CACHE_CONFIG, { optional: true }) ?? DEFAULT_CONFIG;\n return handle(httpRequest, (req) => next(req), config, functionalPerInstanceCache);\n};\n\n/**\n * Class-based interceptor — legacy shim kept for consumers still registering\n * via `HTTP_INTERCEPTORS` / `P3XHttpCacheInterceptorModule.forRoot(...)`.\n * Prefer `p3xHttpCacheInterceptor` (functional) for new code.\n */\n@Injectable()\nexport class HttpCacheInterceptorInterceptor implements HttpInterceptor {\n private readonly cachedData = new Map<string, HttpResponse<any>>();\n private readonly httpCacheConfig: HttpCacheConfig;\n\n constructor(@Inject(P3X_HTTP_CACHE_CONFIG) @Optional() httpCacheConfigToken: HttpCacheConfig | null) {\n this.httpCacheConfig = httpCacheConfigToken ?? DEFAULT_CONFIG;\n }\n\n intercept(httpRequest: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {\n return handle(httpRequest, (req) => next.handle(req), this.httpCacheConfig, this.cachedData);\n }\n}\n","import {\n EnvironmentProviders,\n makeEnvironmentProviders,\n ModuleWithProviders,\n NgModule,\n Provider,\n} from '@angular/core';\nimport { HTTP_INTERCEPTORS } from '@angular/common/http';\n\nimport { HttpCacheInterceptorInterceptor } from './http-cache-interceptor.interceptor';\nimport { P3X_HTTP_CACHE_CONFIG } from './http-cache-config.token';\nimport { HttpCacheConfig } from './http-cache-config';\n\n/**\n * Standalone / functional-provider helper.\n *\n * Usage in `app.config.ts`:\n * ```ts\n * provideHttpClient(withInterceptors([p3xHttpCacheInterceptor])),\n * provideP3xHttpCacheInterceptor({ behavior: CachingHeaders.Cache, store: CachingStore.Global }),\n * ```\n */\nexport function provideP3xHttpCacheInterceptor(\n httpCacheConfig: HttpCacheConfig,\n): EnvironmentProviders {\n return makeEnvironmentProviders([\n { provide: P3X_HTTP_CACHE_CONFIG, useValue: httpCacheConfig },\n ]);\n}\n\n/**\n * Legacy NgModule — kept intact for consumers that still bootstrap via\n * `@NgModule({ imports: [P3XHttpCacheInterceptorModule.forRoot(...)] })`\n * and register the class interceptor through `HTTP_INTERCEPTORS`.\n *\n * New code should prefer `provideP3xHttpCacheInterceptor()` +\n * `p3xHttpCacheInterceptor` (functional).\n */\n@NgModule({\n providers: [\n {\n provide: HTTP_INTERCEPTORS,\n useClass: HttpCacheInterceptorInterceptor,\n multi: true,\n },\n ],\n})\nexport class P3XHttpCacheInterceptorModule {\n static forRoot(httpCacheConfig: HttpCacheConfig): ModuleWithProviders<P3XHttpCacheInterceptorModule> {\n const providers: Provider[] = [\n {\n provide: P3X_HTTP_CACHE_CONFIG,\n useValue: httpCacheConfig,\n },\n ];\n return {\n ngModule: P3XHttpCacheInterceptorModule,\n providers,\n };\n }\n}\n","/*\n * Public API Surface of angular-http-cache-interceptor\n */\n\nexport * from './lib/http-cache-interceptor.module';\nexport * from './lib/http-cache-interceptor.interceptor';\nexport * from './lib/caching-headers.enum';\nexport * from './lib/http-cache-config';\nexport * from './lib/http-cache-config.token';\nexport * from './lib/caching-store.enum';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;AAAA;IACY;AAAZ,CAAA,UAAY,cAAc,EAAA;AACxB,IAAA,cAAA,CAAA,SAAA,CAAA,GAAA,gBAA0B;AAC1B,IAAA,cAAA,CAAA,OAAA,CAAA,GAAA,aAAqB;AACvB,CAAC,EAHW,cAAc,KAAd,cAAc,GAA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
24
  },
25
25
  "sideEffects": false,
26
+ "type": "module",
26
27
  "devDependencies": {
27
- "corifeus-builder": "^2026.4.151"
28
+ "corifeus-builder": "^2026.4.157"
28
29
  },
29
- "version": "2026.4.112",
30
+ "version": "2026.4.117",
30
31
  "description": "🔥 Cache every request in Angular, not only the GET, but all methods of this interceptor, and allows you to interact with the interceptor via specific headers and modify the request, and these specific headers will be not included in the final request",
31
32
  "repository": {
32
33
  "type": "git",