ngx-cache icon indicating copy to clipboard operation
ngx-cache copied to clipboard

add decorator to clear cache

Open M4R1KU opened this issue 7 years ago • 2 comments

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

M4R1KU avatar Aug 06 '18 20:08 M4R1KU

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.

angelnikolov avatar Sep 04 '18 13:09 angelnikolov

@M4R1KU @angelnikolov sorry for the delay, had busy times. feel free to fire a PR and i'll approve.

fulls1z3 avatar Nov 22 '19 00:11 fulls1z3