angelnikolov / ts-cacheable

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

cacheBusterNotifier from another service? #34

Closed kthomas182 closed 5 years ago

kthomas182 commented 5 years ago

Is it possible to set a cacheBusterNotifier from another service?

Ex.

angelnikolov commented 5 years ago

Yes, you can just create a third file and create the subject there like:

export const notifier = new Subject();

Then, where your cache buster service is (orer-entry.service.ts), use it like:

import {notifier} from '../where-you-defined-this';

@CacheBuster({
   cacheBusterNotifier: notifier
})
createNewOrder()

and in the order.service.ts -

import {notifier} from '../where-you-defined-this';

@Cacheable({
   cacheBusterObserver: notifier.asObservable()
})
getOrders()
angelnikolov commented 5 years ago

@kthomas182, let me know if you got any other questions. Closing this for now :)

emrehoumi commented 5 years ago

Hi dear friend, I need your help, can I notify two objects:

const notifier1 = new Subject(); const notifier2 = new Subject();

@CacheBuster({ cacheBusterNotifier: notifier1, notifier2 })

I want to notify two services.

thank you!

emrehoumi commented 5 years ago

I found a solution using this:

//agence.service.ts file export const agenceCache = new Subject();

//societe.service.ts file import { agenceCache } from '../../service/agence/agence.service'; const societeCache = new Subject();

@CacheBuster({ cacheBusterNotifier: societeCache, }) @CacheBuster({ cacheBusterNotifier: agenceCache, }) public updateSociete(societeId: number, societe: Societe) { return this.httpClient.put(${environment.api}/societe/${societeId}, societe); }

thank you!