add decorator to clear cache
I'm submitting a ... (check one with "x")
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[ ] Support request
[x] Feature request
[ ] Documentation issue or request
Current behavior When using the Decorators you are not able to clear the cache or remove a certain key from the cache unless you do it manually by injecting the CacheService.
Expected/desired behavior I expect to have the possibilty to clear the cache via decorator the same way you can add items by calling a method. The new decorator would need the key of the cache which one wants to purge and also the @CacheKey should work with the new decorator.
I thought about something like the CacheEvict Annotation in the Spring Framework https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/cache/annotation/CacheEvict.html
What is the motivation / use case for changing the behavior? The motivation is to not have to inject the CacheService when wanting to clear the cache. An example of a situation where this could be desirable is when you cache a list of an Object of type X and when the user makes a change to this list for instance adding and element or removing one you want to get the new data from the server on the next call instead of having the old value returned.
Environment
-
Angular version: 6.x.x
-
Browser: Browser independent
-
For Tooling issues: irrelevant
-
Others: I would be pleased by an answer and some feedback on the idea. 😄
Feedback:
This might be similar to the CacheBuster decorator of ngx-cacheable
https://github.com/angelnikolov/ngx-cacheable/blob/master/cache-buster.decorator.ts
I.e - just use an arbitrary Subject - subscribe to it from all cache points and emit any value through it when you want to cache bust all subscribers.
@M4R1KU @angelnikolov sorry for the delay, had busy times. feel free to fire a PR and i'll approve.