Question: To add caching inside http is pretty straight forward. ( by passing cache=true )

[http://docs.angularjs.org/api/ng.$http](https://docs.angularjs.org/api/ng/service/$http) has Cache option.

How do I add similar functionality in $resource in angularjs ?

Answer: 
You can also set default cache for $http and thus for $resource which is based on it.

My settings with the excellent [angular-cache](https://github.com/jmdobry/angular-cache) allowing LocalStorage and compliant with $cacheFactory:

```
app.run(function($http, DSCacheFactory) {

    DSCacheFactory('defaultCache', {
        deleteOnExpire: 'aggressive',
        storageMode: 'localStorage' 
    });

    $http.defaults.cache = DSCacheFactory.get('defaultCache');
});

```
I'm using angular-resource 1.5.5 and set my code up the following way:

### Summary

Set *action* as **query**, and since the "query" action is expecting a response deserialized as an array, isArray will need to be explicitly set to true. My understanding is by default ngResource actions expect objects except query.
[See here](https://docs.angularjs.org/error/$resource/badcfg)

**Controller**

```
angular.module("app")
    .controller('myCtrl',['$scope','myService',function($scope, myService) {
        $scope.myData= myService.myResource.query();
    }]);

```

**Service**

```
angular.module('app')
    .factory('myService',['$resource',function($resource){
        var baseUrl = 'http://www.MyExample.com/';
        return{
            myResource:$resource(baseURL + '/myEndpoint/:id', {id:'@id'},{
                'query':{
                    method:'GET',
                    cache:'true',
                    isArray:true
                }}),
        }
    }]);

```