p3x-angular-http-cache-interceptor 2025.4.123 → 2026.4.101
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 +6 -6
- package/fesm2022/p3x-angular-http-cache-interceptor.mjs +8 -8
- package/fesm2022/p3x-angular-http-cache-interceptor.mjs.map +1 -1
- package/package.json +3 -3
- package/types/p3x-angular-http-cache-interceptor.d.ts +29 -0
- package/index.d.ts +0 -5
- package/lib/caching-headers.enum.d.ts +0 -4
- package/lib/caching-store.enum.d.ts +0 -4
- package/lib/http-cache-config.d.ts +0 -6
- package/lib/http-cache-config.token.d.ts +0 -2
- package/lib/http-cache-interceptor.interceptor.d.ts +0 -15
- package/lib/http-cache-interceptor.module.d.ts +0 -9
- package/public-api.d.ts +0 -5
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
|
|
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.101
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
### 🛠️ Built on NodeJs version
|
|
23
23
|
|
|
24
24
|
```txt
|
|
25
|
-
|
|
25
|
+
v24.14.1
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
|
|
@@ -31,7 +31,7 @@ v22.13.1
|
|
|
31
31
|
# 📦 Built on Angular
|
|
32
32
|
|
|
33
33
|
```text
|
|
34
|
-
|
|
34
|
+
21.2.6
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
|
|
@@ -141,7 +141,7 @@ export class AppComponent {
|
|
|
141
141
|
|
|
142
142
|
async loadCached() {
|
|
143
143
|
try {
|
|
144
|
-
const response : any = await this.http.get('https://
|
|
144
|
+
const response : any = await this.http.get('https://network.corifeus.com/public/api/random/32').toPromise()
|
|
145
145
|
this.snack.open(`Will be always the same: ${response.random}`, 'OK')
|
|
146
146
|
} catch(e) {
|
|
147
147
|
this.snack.open(`Sorry, error happened, check the console for the error`, 'OK')
|
|
@@ -151,7 +151,7 @@ export class AppComponent {
|
|
|
151
151
|
|
|
152
152
|
async loadNonCached() {
|
|
153
153
|
try {
|
|
154
|
-
const response : any = await this.http.get('https://
|
|
154
|
+
const response : any = await this.http.get('https://network.corifeus.com/public/api/random/32', {
|
|
155
155
|
headers: {
|
|
156
156
|
[CachingHeaders.NoCache]: '1'
|
|
157
157
|
}
|
|
@@ -213,7 +213,7 @@ All my domains, including [patrikx3.com](https://patrikx3.com), [corifeus.eu](ht
|
|
|
213
213
|
---
|
|
214
214
|
|
|
215
215
|
|
|
216
|
-
[**P3X-ANGULAR-HTTP-CACHE-INTERCEPTOR**](https://corifeus.com/angular-http-cache-interceptor) Build
|
|
216
|
+
[**P3X-ANGULAR-HTTP-CACHE-INTERCEPTOR**](https://corifeus.com/angular-http-cache-interceptor) Build v2026.4.101
|
|
217
217
|
|
|
218
218
|
[](https://www.npmjs.com/package/p3x-angular-http-cache-interceptor) [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QZVM4V6HVZJW6) [](https://www.patrikx3.com/en/front/contact) [](https://www.facebook.com/corifeus.software)
|
|
219
219
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { InjectionToken,
|
|
2
|
+
import { InjectionToken, Inject, Optional, Injectable, NgModule } from '@angular/core';
|
|
3
3
|
import { HttpResponse, HTTP_INTERCEPTORS } from '@angular/common/http';
|
|
4
4
|
import { Observable, of } from 'rxjs';
|
|
5
5
|
import hash from 'object-hash';
|
|
@@ -112,10 +112,10 @@ class HttpCacheInterceptorInterceptor {
|
|
|
112
112
|
}
|
|
113
113
|
*/
|
|
114
114
|
}
|
|
115
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
116
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
115
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: HttpCacheInterceptorInterceptor, deps: [{ token: P3X_HTTP_CACHE_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
116
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: HttpCacheInterceptorInterceptor }); }
|
|
117
117
|
}
|
|
118
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
118
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: HttpCacheInterceptorInterceptor, decorators: [{
|
|
119
119
|
type: Injectable
|
|
120
120
|
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
121
121
|
type: Inject,
|
|
@@ -136,9 +136,9 @@ class P3XHttpCacheInterceptorModule {
|
|
|
136
136
|
]
|
|
137
137
|
};
|
|
138
138
|
}
|
|
139
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
140
|
-
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "
|
|
141
|
-
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "
|
|
139
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: P3XHttpCacheInterceptorModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
140
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.6", ngImport: i0, type: P3XHttpCacheInterceptorModule }); }
|
|
141
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: P3XHttpCacheInterceptorModule, providers: [
|
|
142
142
|
{
|
|
143
143
|
provide: HTTP_INTERCEPTORS,
|
|
144
144
|
useClass: HttpCacheInterceptorInterceptor,
|
|
@@ -146,7 +146,7 @@ class P3XHttpCacheInterceptorModule {
|
|
|
146
146
|
}
|
|
147
147
|
] }); }
|
|
148
148
|
}
|
|
149
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
149
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.6", ngImport: i0, type: P3XHttpCacheInterceptorModule, decorators: [{
|
|
150
150
|
type: NgModule,
|
|
151
151
|
args: [{
|
|
152
152
|
declarations: [],
|
|
@@ -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(\n 'P3X_HTTP_CACHE_CONFIG'\n)\n","import {Inject, Injectable, Optional} from '@angular/core';\nimport { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from '@angular/common/http';\nimport {Observable, of} from 'rxjs';\n\nimport hash from 'object-hash'\nimport {tap} from \"rxjs/operators\";\n\nimport {CachingHeaders} from \"./caching-headers.enum\";\nimport {CachingStore} from \"./caching-store.enum\";\n\nimport {P3X_HTTP_CACHE_CONFIG} from \"./http-cache-config.token\";\nimport {HttpCacheConfig} from \"./http-cache-config\";\n\n\nconst hashOptions = {\n algorithm: 'md5',\n encoding: 'hex'\n}\n\nconst globalCache = new Map<string, any>()\n\n@Injectable()\nexport class HttpCacheInterceptorInterceptor implements HttpInterceptor {\n\n private cachedData = new Map<string, any>()\n\n httpCacheConfig : HttpCacheConfig = {\n behavior: CachingHeaders.Cache,\n store: CachingStore.Global,\n }\n\n getCache(key: string) {\n if (this.httpCacheConfig.store === CachingStore.Global) {\n return globalCache.get(key)\n } else {\n return this.cachedData.get(key)\n }\n }\n\n setCache(key: string, value: any) {\n if (this.httpCacheConfig.store === CachingStore.Global) {\n globalCache.set(key, value)\n } else {\n this.cachedData.set(key, value)\n }\n }\n\n constructor(@Inject(P3X_HTTP_CACHE_CONFIG) @Optional() httpCacheConfigToken: HttpCacheConfig) {\n if (httpCacheConfigToken) {\n this.httpCacheConfig = httpCacheConfigToken\n }\n }\n\n httpToKey(httpRequest: HttpRequest<any>) {\n const body = JSON.parse(JSON.stringify(httpRequest.body))\n const key = httpRequest.method + '@' + httpRequest.urlWithParams + '@' + hash(httpRequest.params, hashOptions) + '@' + hash(body, hashOptions)\n return key\n }\n\n intercept(httpRequest: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {\n\n\n //console.log(httpRequest)\n //console.log('has', httpRequest.headers.has(CachingHeaders.NoCache))\n //console.log('value', httpRequest.headers.get(CachingHeaders.NoCache))\n\n const forcedCache = httpRequest.headers.get(CachingHeaders.Cache) !== null\n const forcedNoneCache = httpRequest.headers.get(CachingHeaders.NoCache) !== null\n\n //console.log('forcedCache', forcedCache, 'forcedNoneCache', forcedNoneCache)\n\n let headers = httpRequest.headers.delete(CachingHeaders.NoCache)\n headers = headers.delete(CachingHeaders.Cache)\n httpRequest = httpRequest.clone({\n headers: headers\n })\n\n if (forcedCache && forcedNoneCache) {\n throw new Error('You cannot use cache and non-cache header at once!')\n } else if (forcedNoneCache || (this.httpCacheConfig.behavior === CachingHeaders.NoCache && !forcedCache)) {\n return next.handle(httpRequest);\n } else if (forcedCache || (this.httpCacheConfig.behavior === CachingHeaders.Cache && !forcedNoneCache)) {\n // Checked if there is cached data for this URI\n const key = this.httpToKey(httpRequest)\n const lastResponse = this.getCache(key);\n if (lastResponse) {\n // In case of parallel requests to same URI,\n // return the request already in progress\n // otherwise return the last cached data\n\n //console.info('http cache interceptor hit cache', key)\n\n return (lastResponse instanceof Observable)\n ? lastResponse : of(lastResponse.clone());\n }\n\n //console.info('http cache interceptor', key)\n\n // If the request of going through for first time\n // then let the request proceed and cache the response\n const requestHandle = next.handle(httpRequest).pipe(\n tap((stateEvent: any) => {\n if (stateEvent instanceof HttpResponse) {\n this.setCache(\n key,\n stateEvent.clone()\n );\n }\n })\n )\n\n // Meanwhile cache the request Observable to handle parallel request\n //this.cachedData.set(key, requestHandle);\n\n return requestHandle;\n } else {\n console.error(this.httpCacheConfig)\n console.error(httpRequest.headers)\n throw new Error('There is a configuration in your setup')\n }\n\n /*\n // Also leave scope of resetting already cached data for a URI\n if (httpRequest.headers.get(\"reset-cache\")) {\n this.cachedData.delete(httpRequest.urlWithParams);\n }\n */\n\n\n }\n}\n","import {ModuleWithProviders, NgModule} from '@angular/core';\nimport { HTTP_INTERCEPTORS } from \"@angular/common/http\";\nimport { HttpCacheInterceptorInterceptor } from './http-cache-interceptor.interceptor'\n\nimport { P3X_HTTP_CACHE_CONFIG } from \"./http-cache-config.token\";\nimport { HttpCacheConfig } from \"./http-cache-config\";\n\n@NgModule({\n declarations: [],\n imports: [\n ],\n providers: [\n {\n provide: HTTP_INTERCEPTORS,\n useClass: HttpCacheInterceptorInterceptor,\n multi: true\n }\n ],\n exports: []\n})\nexport class P3XHttpCacheInterceptorModule {\n\n static forRoot(httpCacheConfig: HttpCacheConfig): ModuleWithProviders<P3XHttpCacheInterceptorModule> {\n return {\n ngModule: P3XHttpCacheInterceptorModule,\n providers: [\n {\n provide: P3X_HTTP_CACHE_CONFIG,\n useValue: httpCacheConfig\n }\n ]\n };\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/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,GAGzB,EAAA,CAAA,CAAA;;ACJD;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,GAGvB,EAAA,CAAA,CAAA;;MCDY,qBAAqB,GAAG,IAAI,cAAc,CACrD,uBAAuB;;ACUzB,MAAM,WAAW,GAAG;AAClB,IAAA,SAAS,EAAE,KAAK;AAChB,IAAA,QAAQ,EAAE;CACX;AAED,MAAM,WAAW,GAAI,IAAI,GAAG,EAAe;MAG9B,+BAA+B,CAAA;AAS1C,IAAA,QAAQ,CAAC,GAAW,EAAA;QAClB,IAAI,IAAI,CAAC,eAAe,CAAC,KAAK,KAAK,YAAY,CAAC,MAAM,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AAA,QAAQ,EAAE,+BAA+B;AACzC,gBAAA,KAAK,EAAE;AACR;AACF,SAAA,EAAA,CAAA,CAAA;;2FAGU,6BAA6B,EAAA,UAAA,EAAA,CAAA;kBAbzC,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,YAAY,EAAE,EAAE;AAChB,oBAAA,OAAO,EAAE,EACR;AACD,oBAAA,SAAS,EAAE;AACT,wBAAA;AACE,4BAAA,OAAO,EAAE,iBAAiB;AAC1B,4BAAA,QAAQ,EAAE,+BAA+B;AACzC,4BAAA,KAAK,EAAE;AACR;AACF,qBAAA;AACD,oBAAA,OAAO,EAAE;AACV,iBAAA;;;ACnBD;;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(\n 'P3X_HTTP_CACHE_CONFIG'\n)\n","import {Inject, Injectable, Optional} from '@angular/core';\nimport { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from '@angular/common/http';\nimport {Observable, of} from 'rxjs';\n\nimport hash from 'object-hash'\nimport {tap} from \"rxjs/operators\";\n\nimport {CachingHeaders} from \"./caching-headers.enum\";\nimport {CachingStore} from \"./caching-store.enum\";\n\nimport {P3X_HTTP_CACHE_CONFIG} from \"./http-cache-config.token\";\nimport {HttpCacheConfig} from \"./http-cache-config\";\n\n\nconst hashOptions = {\n algorithm: 'md5',\n encoding: 'hex'\n}\n\nconst globalCache = new Map<string, any>()\n\n@Injectable()\nexport class HttpCacheInterceptorInterceptor implements HttpInterceptor {\n\n private cachedData = new Map<string, any>()\n\n httpCacheConfig : HttpCacheConfig = {\n behavior: CachingHeaders.Cache,\n store: CachingStore.Global,\n }\n\n getCache(key: string) {\n if (this.httpCacheConfig.store === CachingStore.Global) {\n return globalCache.get(key)\n } else {\n return this.cachedData.get(key)\n }\n }\n\n setCache(key: string, value: any) {\n if (this.httpCacheConfig.store === CachingStore.Global) {\n globalCache.set(key, value)\n } else {\n this.cachedData.set(key, value)\n }\n }\n\n constructor(@Inject(P3X_HTTP_CACHE_CONFIG) @Optional() httpCacheConfigToken: HttpCacheConfig) {\n if (httpCacheConfigToken) {\n this.httpCacheConfig = httpCacheConfigToken\n }\n }\n\n httpToKey(httpRequest: HttpRequest<any>) {\n const body = JSON.parse(JSON.stringify(httpRequest.body))\n const key = httpRequest.method + '@' + httpRequest.urlWithParams + '@' + hash(httpRequest.params, hashOptions) + '@' + hash(body, hashOptions)\n return key\n }\n\n intercept(httpRequest: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {\n\n\n //console.log(httpRequest)\n //console.log('has', httpRequest.headers.has(CachingHeaders.NoCache))\n //console.log('value', httpRequest.headers.get(CachingHeaders.NoCache))\n\n const forcedCache = httpRequest.headers.get(CachingHeaders.Cache) !== null\n const forcedNoneCache = httpRequest.headers.get(CachingHeaders.NoCache) !== null\n\n //console.log('forcedCache', forcedCache, 'forcedNoneCache', forcedNoneCache)\n\n let headers = httpRequest.headers.delete(CachingHeaders.NoCache)\n headers = headers.delete(CachingHeaders.Cache)\n httpRequest = httpRequest.clone({\n headers: headers\n })\n\n if (forcedCache && forcedNoneCache) {\n throw new Error('You cannot use cache and non-cache header at once!')\n } else if (forcedNoneCache || (this.httpCacheConfig.behavior === CachingHeaders.NoCache && !forcedCache)) {\n return next.handle(httpRequest);\n } else if (forcedCache || (this.httpCacheConfig.behavior === CachingHeaders.Cache && !forcedNoneCache)) {\n // Checked if there is cached data for this URI\n const key = this.httpToKey(httpRequest)\n const lastResponse = this.getCache(key);\n if (lastResponse) {\n // In case of parallel requests to same URI,\n // return the request already in progress\n // otherwise return the last cached data\n\n //console.info('http cache interceptor hit cache', key)\n\n return (lastResponse instanceof Observable)\n ? lastResponse : of(lastResponse.clone());\n }\n\n //console.info('http cache interceptor', key)\n\n // If the request of going through for first time\n // then let the request proceed and cache the response\n const requestHandle = next.handle(httpRequest).pipe(\n tap((stateEvent: any) => {\n if (stateEvent instanceof HttpResponse) {\n this.setCache(\n key,\n stateEvent.clone()\n );\n }\n })\n )\n\n // Meanwhile cache the request Observable to handle parallel request\n //this.cachedData.set(key, requestHandle);\n\n return requestHandle;\n } else {\n console.error(this.httpCacheConfig)\n console.error(httpRequest.headers)\n throw new Error('There is a configuration in your setup')\n }\n\n /*\n // Also leave scope of resetting already cached data for a URI\n if (httpRequest.headers.get(\"reset-cache\")) {\n this.cachedData.delete(httpRequest.urlWithParams);\n }\n */\n\n\n }\n}\n","import {ModuleWithProviders, NgModule} from '@angular/core';\nimport { HTTP_INTERCEPTORS } from \"@angular/common/http\";\nimport { HttpCacheInterceptorInterceptor } from './http-cache-interceptor.interceptor'\n\nimport { P3X_HTTP_CACHE_CONFIG } from \"./http-cache-config.token\";\nimport { HttpCacheConfig } from \"./http-cache-config\";\n\n@NgModule({\n declarations: [],\n imports: [\n ],\n providers: [\n {\n provide: HTTP_INTERCEPTORS,\n useClass: HttpCacheInterceptorInterceptor,\n multi: true\n }\n ],\n exports: []\n})\nexport class P3XHttpCacheInterceptorModule {\n\n static forRoot(httpCacheConfig: HttpCacheConfig): ModuleWithProviders<P3XHttpCacheInterceptorModule> {\n return {\n ngModule: P3XHttpCacheInterceptorModule,\n providers: [\n {\n provide: P3X_HTTP_CACHE_CONFIG,\n useValue: httpCacheConfig\n }\n ]\n };\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/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;;ACUzB,MAAM,WAAW,GAAG;AAClB,IAAA,SAAS,EAAE,KAAK;AAChB,IAAA,QAAQ,EAAE;CACX;AAED,MAAM,WAAW,GAAI,IAAI,GAAG,EAAe;MAG9B,+BAA+B,CAAA;AAS1C,IAAA,QAAQ,CAAC,GAAW,EAAA;QAClB,IAAI,IAAI,CAAC,eAAe,CAAC,KAAK,KAAK,YAAY,CAAC,MAAM,EAAE;AACtD,YAAA,OAAO,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC;QAC7B;aAAO;YACL,OAAO,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,QAAQ,EAAE,+BAA+B;AACzC,gBAAA,KAAK,EAAE;AACR;AACF,SAAA,EAAA,CAAA,CAAA;;2FAGU,6BAA6B,EAAA,UAAA,EAAA,CAAA;kBAbzC,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,YAAY,EAAE,EAAE;AAChB,oBAAA,OAAO,EAAE,EACR;AACD,oBAAA,SAAS,EAAE;AACT,wBAAA;AACE,4BAAA,OAAO,EAAE,iBAAiB;AAC1B,4BAAA,QAAQ,EAAE,+BAA+B;AACzC,4BAAA,KAAK,EAAE;AACR;AACF,qBAAA;AACD,oBAAA,OAAO,EAAE;AACV,iBAAA;;;ACnBD;;AAEG;;ACFH;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
"tslib": "^2.0.3"
|
|
13
13
|
},
|
|
14
14
|
"module": "fesm2022/p3x-angular-http-cache-interceptor.mjs",
|
|
15
|
-
"typings": "
|
|
15
|
+
"typings": "types/p3x-angular-http-cache-interceptor.d.ts",
|
|
16
16
|
"exports": {
|
|
17
17
|
"./package.json": {
|
|
18
18
|
"default": "./package.json"
|
|
19
19
|
},
|
|
20
20
|
".": {
|
|
21
|
-
"types": "./
|
|
21
|
+
"types": "./types/p3x-angular-http-cache-interceptor.d.ts",
|
|
22
22
|
"default": "./fesm2022/p3x-angular-http-cache-interceptor.mjs"
|
|
23
23
|
}
|
|
24
24
|
},
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"corifeus-builder": "^2025.4.135"
|
|
28
28
|
},
|
|
29
|
-
"version": "
|
|
29
|
+
"version": "2026.4.101",
|
|
30
30
|
"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
31
|
"repository": {
|
|
32
32
|
"type": "git",
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { ModuleWithProviders, InjectionToken } from '@angular/core';
|
|
3
|
+
|
|
4
|
+
declare enum CachingHeaders {
|
|
5
|
+
NoCache = "x-p3x-no-cache",
|
|
6
|
+
Cache = "x-p3x-cache"
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare enum CachingStore {
|
|
10
|
+
Global = 0,
|
|
11
|
+
PerModule = 1
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface HttpCacheConfig {
|
|
15
|
+
behavior: CachingHeaders;
|
|
16
|
+
store: CachingStore;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare class P3XHttpCacheInterceptorModule {
|
|
20
|
+
static forRoot(httpCacheConfig: HttpCacheConfig): ModuleWithProviders<P3XHttpCacheInterceptorModule>;
|
|
21
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<P3XHttpCacheInterceptorModule, never>;
|
|
22
|
+
static ɵmod: i0.ɵɵNgModuleDeclaration<P3XHttpCacheInterceptorModule, never, never, never>;
|
|
23
|
+
static ɵinj: i0.ɵɵInjectorDeclaration<P3XHttpCacheInterceptorModule>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare const P3X_HTTP_CACHE_CONFIG: InjectionToken<unknown>;
|
|
27
|
+
|
|
28
|
+
export { CachingHeaders, CachingStore, P3XHttpCacheInterceptorModule, P3X_HTTP_CACHE_CONFIG };
|
|
29
|
+
export type { HttpCacheConfig };
|
package/index.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
|
|
2
|
-
import { Observable } from 'rxjs';
|
|
3
|
-
import { HttpCacheConfig } from "./http-cache-config";
|
|
4
|
-
import * as i0 from "@angular/core";
|
|
5
|
-
export declare class HttpCacheInterceptorInterceptor implements HttpInterceptor {
|
|
6
|
-
private cachedData;
|
|
7
|
-
httpCacheConfig: HttpCacheConfig;
|
|
8
|
-
getCache(key: string): any;
|
|
9
|
-
setCache(key: string, value: any): void;
|
|
10
|
-
constructor(httpCacheConfigToken: HttpCacheConfig);
|
|
11
|
-
httpToKey(httpRequest: HttpRequest<any>): string;
|
|
12
|
-
intercept(httpRequest: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>>;
|
|
13
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<HttpCacheInterceptorInterceptor, [{ optional: true; }]>;
|
|
14
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<HttpCacheInterceptorInterceptor>;
|
|
15
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ModuleWithProviders } from '@angular/core';
|
|
2
|
-
import { HttpCacheConfig } from "./http-cache-config";
|
|
3
|
-
import * as i0 from "@angular/core";
|
|
4
|
-
export declare class P3XHttpCacheInterceptorModule {
|
|
5
|
-
static forRoot(httpCacheConfig: HttpCacheConfig): ModuleWithProviders<P3XHttpCacheInterceptorModule>;
|
|
6
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<P3XHttpCacheInterceptorModule, never>;
|
|
7
|
-
static ɵmod: i0.ɵɵNgModuleDeclaration<P3XHttpCacheInterceptorModule, never, never, never>;
|
|
8
|
-
static ɵinj: i0.ɵɵInjectorDeclaration<P3XHttpCacheInterceptorModule>;
|
|
9
|
-
}
|