I created a service using CacheFactory. I expected it to be singleton. I inject it into the controller and it works fine within the controller. But as soon as I go to another page with a different scope, I don't seem to have any cache values that I saved in one controller in another area. Should the CacheFactory behavior be single, where I have the same cached objects, where I insert the CacheService?
This is my example service:
angular.module('MyService', []).factory('CacheService', function($cacheFactory) {
return $cacheFactory('cacheService', {
capacity: 3
})
});
Then in my controller:
function MyController($scope, CacheService) {
var results= CacheService.get('storedvalue');
if(!results){
CacheService.put('storedvalue', results);
alert('results not stored');
}
else
alert('results stored');
}
source
share