2

I'm using the angularjs-rails-resource project to wrap my http rest services. One thing I didn't find in documentation is regarding cache, some of my methods should access the server only once and cache their response.

Is there an easy way to achieve this?

Chen Kinnrot
  • 20,609
  • 17
  • 79
  • 141

1 Answers1

2

You can pass options to $http through your resource configuration (i.e. httpConfig) like so:

return railsResourceFactory({
  url: '/books',
  name: 'book',
  httpConfig: {
    cache: true
  }
});
  • And how can I invalidate the cache ? – Chen Kinnrot Jun 26 '15 at 06:55
  • You'll need to provide your own cache mechanism (see [here](https://github.com/angular/angular.js/issues/2079#issuecomment-14216841)). Here's one popular replacement for Angular's $cacheFactory that works with `$http`: https://github.com/jmdobry/angular-cache#using-angular-cache-with-http – Sebastien Rothlisberger Jun 29 '15 at 13:44