Closed exc414 closed 5 years ago
This is due to the fact that I am doing a deep copy on the parameters you call the decorated method with because otherwise, if you pass an object to your method, someone could later mutate that object, which will automatically propagate to the cached object inside the decorator, because it will be the same reference. Let me think how to handle this and I will get back to you :)
So, the problematic line is here.
The issue is that your makeRequest
method uses angular's HttpParams
construct.
Three ways we can solve this:
HttpParams
, but rather use a plain javascript object since Angular also supports that:
request(method: string, url: string, options: {
params?: HttpParams | {
[param: string]: string | string[];
};
}
cacheConfig
parameter - mutableParameters: boolean
which will dictate if the parameters should be mutable and if such - we won't copy them but leave them as they are.
@exc414 Let me know what you think :)Hello,
So I went the second route and did not depend on HttpParams. Works fine then. Thank you very much for your help.
Hello,
I found this library from an article here
I added the @Cacheable annotation to a request method that makes a GET request to an API.
The base URL looks like this when no @Cacheable is used :
The HttpParams have a page and size parameters. The whole URL looks like :
However when adding @Cacheable the request URL looks like this (web console) :
I then get no results back as the server returns a 400 error. Since that end point does not exist.
This is what my whole service looks like.
I am using angular 7 and the new HTTP Client. Thank you.