angelnikolov / ts-cacheable

Observable/Promise Cache Decorator
https://npmjs.com/package/ts-cacheable
ISC License
340 stars 42 forks source link

In some url pattern it is not working #19

Closed 234akshay closed 5 years ago

234akshay commented 5 years ago

api url: products/3?page=1

3: categoryid

in above api url cache response getting empty but normally api call i get response

Api response: apiresponse

cached response: cachedresponse

angelnikolov commented 5 years ago

Hey @234akshay, can you provide some snippets of code which led to this?

234akshay commented 5 years ago

@Cacheable({ async: true, maxCacheCount: 1000, maxAge: 7200000 }) callGetAPI(url: string) { return this.http.get(environment.apiUrl + url, this.headers()) .pipe(map( data => { return data; } )); }

// this way i am doing it is correct way?

angelnikolov commented 5 years ago

And you are calling this twice with the same url?

On Fri, 2 Nov 2018 at 13:47, 234akshay notifications@github.com wrote:

@Cacheable https://github.com/Cacheable({ async: true, maxCacheCount: 1000, maxAge: 7200000 }) callGetAPI(url: string) { return this.http.get(environment.apiUrl + url, this.headers()) .pipe(map( data => { return data; } )); }

// this way i am doing it is correct way?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/angelnikolov/ngx-cacheable/issues/19#issuecomment-435353843, or mute the thread https://github.com/notifications/unsubscribe-auth/ACjSOwY7U0D9rKiMXk-uqS3SF_PByLXyks5urDDZgaJpZM4YLLo1 .

234akshay commented 5 years ago

no i am calling once at a time but after sometime hit same api it is getting empty data because it is coming from cache. i don't know but at same time it is calling only once not twice that i am sure.

angelnikolov commented 5 years ago

Can you check the network tab and confirm that no 2nd request is sent? It doesn't make sense that just the data is empty and the rest of the payload is the same.. Also you have some other differences in the payload like to and total so I guess that's a new request. I see that you are using one generic method that you maybe use for all [GET]s. You are also using a maxCacheCount which should cache 1000 calls. It looks like you are calling different URLs between the first and the second call, and the second payload is coming from the server.

234akshay commented 5 years ago

thanks for giving quick reply i check on Monday and give response.