In AngularJS, how would you cache the data (for example, a list of top 10 news of today) you receive from Java?

I am fetching the list of news from the Backend and want to cache them and display them in HTML5 using the AngularJS.

I am new to Angular and don't know the correct way to do this. is it possible to cache this data or not. Please suggest.

if are not allowed to comment here you can comment here as well : http://blog.grepruby.com/2014/09/in-angularjs-how-would-you-cache-data.html

Simplest approach for your problem would be making a angular service and using $cacheFactory.

app.service('NewsService', function ($http) {
  return {
    getTopTen: function () {
    // Get top 10 news from backend
      return $http.get('/api/news/top10', {
        cache: true;
      });
    }
  };
});

NewsService.getTopTen(); // 100ms
NewsService.getTopTen(); // 1ms
$cacheFactory.get('$http').get('/api/news/top10'); // cached item

$cachefactory doesn't support XY what now ?

If you need something more flexible then use : http://jmdobry.github.io/angular-cache/

If you just want to avoid unecessary calls to your webservice, do not rebuild caching in your application. You should rather use HTTPs caching functionality and your browser support of it by setting the correct HTTP caching headers in your Server:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html