removed interceptor logic, enabling browser caching only
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/pr-dev Build queued...

This commit is contained in:
2026-06-12 18:31:29 +02:00
parent 0d16159a23
commit 2b6f6bfc51
2 changed files with 1 additions and 64 deletions
+1 -2
View File
@@ -11,7 +11,6 @@ import { MAT_FORM_FIELD_DEFAULT_OPTIONS } from '@angular/material/form-field';
import { MatPaginatorIntl } from '@angular/material/paginator';
import { PaginatorIntl } from './shared/utils/paginatorIntl';
import { provideEchartsCore } from 'ngx-echarts';
import { cachingInterceptor } from './shared/interceptors/caching.interceptor';
registerLocaleData(locale);
@@ -24,7 +23,7 @@ export const appConfig: ApplicationConfig = {
},
{ provide: MatPaginatorIntl, useClass: PaginatorIntl },
provideRouter(routes),
provideHttpClient(withInterceptors([authenticationInterceptor,cachingInterceptor])),
provideHttpClient(withInterceptors([authenticationInterceptor])),
// provideApi('/inse-service'),
provideAnimationsAsync(),
provideEchartsCore({ echarts: () => import('echarts') }),
@@ -1,62 +0,0 @@
import {
HttpInterceptorFn,
HttpResponse,
HttpErrorResponse
} from '@angular/common/http';
import { catchError, of, tap, throwError } from 'rxjs';
// here we do store our etags and responses from server.
const etagStore = new Map<string, string>();
const responseCache = new Map<string, any>();
export const cachingInterceptor: HttpInterceptorFn = (req, next) => {
if (req.method !== 'GET') {
return next(req);
}
// Do we have an ETag for the corresponding request?
const cacheKey = req.urlWithParams;
const etag = etagStore.get(cacheKey);
// If yes, set header to "If-None-Match" to let the server know we've got already an ETag.
const modifiedReq = etag
? req.clone({
setHeaders: {
'If-None-Match': etag
}
})
: req;
// On server response:
return next(modifiedReq).pipe(
tap(event => {
if (event instanceof HttpResponse) {
const responseEtag = event.headers.get('ETag');
// update the ETag and response body for our request
console.log("FROM NEW BACKEND CALL , UPDATING ETAG",responseEtag)
if (event.status === 200 && responseEtag) {
etagStore.set(cacheKey, responseEtag);
responseCache.set(cacheKey, event.body);
}
}
}),
// handle 304 separately (no data changes)
catchError(err => {
if ( // Server responded with 304 -> ETag hasnt changed -> use cached response body
err instanceof HttpErrorResponse &&
err.status === 304 &&
responseCache.has(cacheKey)
) {
console.log("FROM CACHE!",cacheKey)
return of(
new HttpResponse({
body: responseCache.get(cacheKey),
status: 200,
statusText: 'OK (cached)',
url: req.urlWithParams
})
);
}
return throwError(() => err);
})
);
};