I have a angular project with a angular-data to work with my Restful API.
my situation is as following:
in my service I return a defineresource in my controller I use service.defineresource.findAll().then
it all works fine but here is my question. when new data is added to the server how do I update the cache or add the new data to my cache.
Please advice
code: //in service.js
.factory('Service', function(DS) {
DS.defineresource({
name: 'items'
endpoint:'api/v2/users'
});
});
//in controller.js
.controller('MainCtrl', function($scope, Service) {
Service.findAll().then(function (data) {
$scope.items = data
});
});
my code is above fetches all the data when I load it first time, but after the initial loading it only loads from the cache. My question is there a way to sync and fetch new data without destroying the cache.
To force the refresh of the data from the backend you need to set
bypassCache: truein the options. If you don't pass this then angular-data will load from cache. This is documented in the api documentation.To refresh the data every 15 minutes use
$timeoutwith 900000 milliseconds. To have a button to refresh use a scope function that will be called from ang-clickon a button.