Force invalidation of one item
Closed this issue · 5 comments
Hello, nice work!
I would like to ask you if there's any way to force the removal or refresh of one individual item.
I don't know an exact expire time, but I know when the item becomes obsolete, so I want to remove it then.
Sorry, I didn't found another way to communicate with you.
Thanks in advance
The answers to your questions should be found here. The mailing list can be found here.
Sounds like you may be looking for Cache#remove(key) or Cache#touch(key). Setting deleteOnExpire
to "aggressive"
will remove items from the cache when they expire.
Closing because I’m not sure this is an issue, if you are convinced that this is really a bug, please feel free to re-open the issue and add more information:
- good - Your versions of Angular, Angular-cache, etc, relevant console logs/error, code examples that revealed the issue
- better - A plnkr, fiddle, or bin that demonstrates the issue
- best - A Pull Request that fixes the issue, including test coverage for the issue and the fix
Otherwise support is done via the mailing list.
I would like some clarification on this as well. It's currently the only question preventing me from switching to angular-cache.
When I use angular-cache with $http, I might want to force a cache refresh. How do I tell angular-cache or $http that regardless of whether a value is already cached, grab a new item and overwrite the cache?
I could definitely just call Cache.remove(), but I'm not quite sure what the key $http creates...
but I'm not quite sure what the key $http creates...
From here: https://docs.angularjs.org/api/ng/service/$http#caching
The cache key is the request URL including search parameters; headers are not considered.
So, just call remove
on the cache, using "the request URL including search parameters" as the key.
Awesome! I tried looking in the Angular $http docs, but I guess I'm blind. Now I'm curious how to configure $http to provide a hash for the key rather than the URL... I don't want my API endpoints to be so visible through dev tools.
Might also be worth showing an example in the documentation of of refreshing the cache before executing a request with $http. I know others have this question too. In my case, I almost passed up on angular-cache because I couldn't find anything mentioned.
@AndrewCraswell Go to the Readme of this repo and look for this section
Do your own caching while using the $http service:
It shows adding results to the cache yourself (as opposed to letting $http add stuff to the cache). This lets you control the keys, since you don't want your endpoints exposed in your keys.
If you have other questions, suggestions, or PRs you'd like to submit, please open a separate issue, as starting new divergent conversations on old closed issues isn't the best.