As per the AngularJS documentation, $resource service now has support for caching as well.
cache – {boolean|Cache} – If true, a default $http cache will be used to cache the GET request, otherwise if a cache instance built with $cacheFactory, this cache will be used for caching.
So I may write $resource as follows:
app.factory('myResourceWithCache', function($resource, $cacheFactory) {
var myCache = $cacheFactory('MyCache');
return $resource(apiBaseUrl + '/myservice/:id', {id: '@id'}, {
'get': { method:'GET', cache: myCache },
'query': { method:'GET', cache: myCache , isArray:true }
});
});
What I want to know is that:
I tried AngularJS documentation and other stackoverflow threads but did not find any answer for this. Please help.
I'm not sure if you still need answer for this one year old question.
Angular Documentation $http - Caching section doesn't mention about custom key
and from the $http library, either custom or default cache will be using this line to "put" cache which is the request url.
so answer for your questions: