Angularjs $resource Cache

早过忘川 提交于 2019-12-02 18:58:15

问题


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

来源:https://stackoverflow.com/questions/33654437/angularjs-resource-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!