angelnikolov/ts-cacheable

Caching distinct function results

Closed this issue · 7 comments

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!

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

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).

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

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

@fabioseno Can you provide more information?

@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!

Closing as resolved.