I am currently working on an Angular application that is connected to a REST API. In order to minimize the number of requests made, I have implemented a method to store all data in the local storage.
.factory('$localstorage', ['$window', function($window) {
return {
set: function(key, value) {
var object = {value: value, timestamp: new Date().getTime()}
$window.localStorage[key] = JSON.stringify(object);
},
setObject: function(key, value) {
var object = {value: value, timestamp: new Date().getTime()}
$window.localStorage[key] = JSON.stringify(object);
},
}
}]);
As new data is expected every Monday, my goal is to determine if the data stored in the local storage is older than 7 days and if the current day of the week is Monday.
If these conditions are met, then the data should be refreshed. I am seeking for suggestions on how to tackle this simple problem. Any ideas?