Please read the instruction of @ngneat/cashew before answering this question from here @ngneat/cashew
The Idea is simple instead of doing this in service level like this,
this.httpClient.get<Posts>(`http://localhost:3000/posts/${id}`,{context:withCache()});
I want to make a global interceptor. Here is my code snippet,
# Config of Interceptor
{
provide: HTTP_INTERCEPTORS, useClass: CacheInterceptor, multi: true
}
# Here is CacheInterceptor
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const modifiedRequest = request.clone(
{context: withCache()}
);
return next.handle(modifiedRequest);
}
I want to do this because adding { context : withCache() } in every service's method is repetitive, otherwise in a existing project it it too much time killer. That's why I want achive this via making a custom Interceptor. Does it possible to achieve ?