$cacheFactory :
A cache is object, this will store and get cache data. Why we can use cache ? the reason is increase the speed of retrieve data access. Because increase the performance of application.This Cache have 5 methods:
info() - The details about cache object properties.
put(key, value) - Push the details of key,value object;
get(key) - Get the details of pushed objects;
remove(key) - Remove a specific object;
removeAll() - Remove all pushed objects;
destroy() - Clear the cache object;
Angular Code :
<div ng-app="cacheApp">
<div ng-controller="CacheCtrl">
Data {{information()}}
</div>
</div>
var app = angular.module("cacheApp", [])
app.factory('myCache' , function($cacheFactory) {
return $cacheFactory('mycache' , { capacity : 3 })
});
app.controller('CacheCtrl', function($scope, myCache) {
var data = {id:10, name:"selva"};
myCache.put("nameDetails", data.name);
myCache.put("myId", data.id);
myCache.put("myId2", 20);
myCache.put("myId3", 25);
console.log("my cache =>"+myCache.get("nameDetails"));
$scope.information = function() {
return myCache.info();
};
});
Comments
Post a Comment