From 2b6f6bfc51fb341ea5c4366637aafdbdc6482a28 Mon Sep 17 00:00:00 2001 From: genja Date: Fri, 12 Jun 2026 18:31:29 +0200 Subject: [PATCH] removed interceptor logic, enabling browser caching only --- webapp/src/app/app.config.ts | 3 +- .../interceptors/caching.interceptor.ts | 62 ------------------- 2 files changed, 1 insertion(+), 64 deletions(-) delete mode 100644 webapp/src/app/shared/interceptors/caching.interceptor.ts diff --git a/webapp/src/app/app.config.ts b/webapp/src/app/app.config.ts index 596122e4..7aaeef9e 100644 --- a/webapp/src/app/app.config.ts +++ b/webapp/src/app/app.config.ts @@ -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') }), diff --git a/webapp/src/app/shared/interceptors/caching.interceptor.ts b/webapp/src/app/shared/interceptors/caching.interceptor.ts deleted file mode 100644 index 4b60ec94..00000000 --- a/webapp/src/app/shared/interceptors/caching.interceptor.ts +++ /dev/null @@ -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(); -const responseCache = new Map(); - -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); - }) - ); -}; \ No newline at end of file