angelnikolov / ts-cacheable

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

Caching distinct function results #76

Closed fabioseno closed 4 years ago

fabioseno commented 4 years ago

Hi, I have two methods under the same service as below:

@Cacheable({
    cacheBusterObserver: myCacheBuster
})
listAll() {
    // return response data here
}

@Cacheable({
    cacheBusterObserver: myCacheBuster
})
list(filter) {
    // return filtered response data
}

The cache is only working if I hit subsequent calls to the same function. By having different functions, wasn't it supposed to have both results cached?

Apparently it works if I set the maxCacheCount to more than 1, but I understand that it should affect only combinations of cache under the same function. Am I right?

GlobalCacheConfig.maxCacheCount = 2;

Thanks!

angelnikolov commented 4 years ago

Not sure I understand. Both methods are independent in terms of caching. If you call once listAll, you obviously wont' have cached results. Every other call of the same parameters will be. Same for list

fabioseno commented 4 years ago

They are independent functions, but they are not behaving as expected.

The behaviour: 1) Call listAll function -> executes HTTP request (OK) 2) Call listAll function again -> Data from cache (OK) 3) Call list function with some param -> executes HTTP request (OK) 4) Call listAll function -> executes HTTP request (ERROR).

deyanpeychev00 commented 4 years ago

@fabioseno just curious, how do you check whether data is returned from cache or not?

angelnikolov commented 4 years ago

@fabioseno Can you provide an example in stackblitz? Also, why do you need the cacheBusterObservers?

angelnikolov commented 4 years ago

@fabioseno Can you provide more information?

fabioseno commented 4 years ago

@deyanpeychev00 I just got some time to get back to this issue and realized it's working as expected now! I created a stackblitz (https://stackblitz.com/edit/angular-vzxqvv) and everything is alright.

Thank you all!

angelnikolov commented 4 years ago

Closing as resolved.