angelnikolov / ts-cacheable

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

Burst Multiple cache using cacheBusterNotifier #81

Closed saurabh47 closed 4 years ago

saurabh47 commented 4 years ago

Hello Devs,

Is it possible to burst multiple cache using cacheBusterNotifier.

I'm using this to burst single cache

  @CacheBuster({
    cacheBusterNotifier: cacheBuster$
  })

I know there is one another way to burst multiple cache by calling method.

burstCache(){
 cacheBuster1$.next();
 cacheBuster2$.next();
}

It will be helpful . if we can pass the array of subject to cacheBusterNotifier. something like this

  @CacheBuster({
    cacheBusterNotifier: [cacheBuster1$,cacheBuster2$]
  })

I'm not sure its possible with the decorators.

if I missed something. please suggest some other possible ways to do cache bursting.

Thank you so much for this library

angelnikolov commented 4 years ago

@saurabh47 This has been asked before and right now there isn't a way. You can of course create a common Subject and subscribe other subjects to it. Similar to your burstCache() method. Something like:

 @CacheBuster({
    cacheBusterNotifier: commonCacheBuster$
  })

And then have other cacheBusterObservers subscribe to it like commonCacheBuster$.subscribe(event=>specificCacheBuster.next()),commonCacheBuster$.subscribe(event=>specificCacheBuster2.next()) and etc.. THen use those like:

@Cacheable(
{
   cacheBusterObserver: specificCacheBuster2
}
)
saurabh47 commented 4 years ago

Thanks @angelnikolov