Is there a way to find out the actual URL used during an action method call of an Angular $resource? I'm trying to decorate the default factory to implement my own caching mechanism for resources as I find the one that comes out of the box too limited for what I'm trying to do.
So I'm wrapping the get
method that $resource creates to query the cache and if that gave me nothing, hit the server and cache the response. It makes sense to use the URL as the cache key, but how can I get this?
Here's some code to illustrate:
var _get = Resource.get;
Resource.get = function() {
var self = this;
if (Resource.cache && Resource.cache.get(WHAT_TO_PUT_HERE?))
return Resource.cache.get(WHAT_TO_PUT_HERE?);
var result = _get.apply(this, arguments);
result.$promise.then(function cacheResult(resource) {
Resource.cache.put(WHAT_TO_PUT_HERE?, resource);
return resource;
});
return result;
};
I am aware of this excellent answer on StackOverflow which uses interceptors, but I would prefer to keep the relevant code in one place (the example method I posted).