Closed deyanpeychev00 closed 4 years ago
Yes, you can provide a cacheBusterNotifier: subject
in the @Cacheable
config and next on it when you want a method's cache to be evicted.
https://github.com/angelnikolov/ngx-cacheable#cache-busting
Just checked that, but I seem to get an error:
Argument of type '{ cacheBusterNotifier: Subject
Here is how I have implemented it:
const allUsersCacheBuster$ = new Subject<void>();
@Cacheable({
cacheBusterObserver: allUsersCacheBuster$
})
getAllUsers(query): Observable<HttpResponse<any>> {
// gets data for users
}
@Cacheable({
cacheBusterNotifier: allUsersCacheBuster$
})
createUser(userData): Observable<any> {
// creates new user
}
Update:
Ignore my comment with the error message, just made it work with removing the cacheBusterNotifier
property from the @Cacheable()
decorator and invoking allUsersCacheBuster$.next()
in the methods that I want to clear the specific cache.
The issue can now be marked as closed or remain here if considered as helpful to someone. :)
Maybe this should be documented. I tried cacheBusterNotifier as well like the documentation and it didn't work.
Does not work:
@Cacheable({
cacheBusterNotifier: allUsersCacheBuster$
})
createUser(userData): Observable<any> {
// creates new user
return EMPTY;
}
Works:
createUser(userData): Observable<any> {
allUsersCacheBuster$.next();
return EMPTY;
}
Really like your project and the fact that it's a Bulgarian one!
Just a question: Having read the documentation and found that the cache can be busted using:
Is there a way that I can bust the cache only for a specific http request?