0

I have a more generic implementation of $resource as "Datarepository" factory in my application and all the REST API calls calls this factory to do the "REST" operation

myapp.factory('DataRepository', function ($resource) {
 var resourceFactory = function (url) {
        return $resource(url, {}, {
            update: { method: 'PUT' }
        }
        );
    }
 return {
        invokeAPI: resourceFactory
    }
});

A sample call to the repository get method looks like this

DataRepository.invokeAPI(myappURL).get();

For a specific scenario alone, i would like to "cache" the data.. I dont want to disturb the "Datarepository" factory method and just would like to add the cache paramter for those URL's which i would like to cache the data

something like this

DataRepository.invokeAPI(myappURL).get({cache:true});

The above implementation doesnt work the way it is expected and it passed the cache as query string paramter. I read the angularjs documentation for $resource. I got it how to set it at $resource level but i m not sure how to pass it to the resource through normal function call without disturbing the Factory implementation

3
  • Which Angular version are you using? Commented Nov 12, 2015 at 20:59
  • @LordTribual I m using 1.3.15 version Commented Nov 12, 2015 at 21:09
  • As war as I know you have to setup the get with caching by calling $resourceand passing along options. Commented Nov 14, 2015 at 8:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.