1、Angular中的$cacheFactory的作用:
(1)put(key,value);
在缓存对象中插入一个键值对(key,value)。
(2)get(key);
在缓存对象中通过指定key获取对应的值。
(3)romove(key);
在缓存对象中通过指定key删除对应的值。
(4)removeAll();
删除缓存对象中所有的键值对。
(5)destroy();
销毁这个缓存对象。
(6)info();
获取缓存对象信息(id,size)。
value:所有类型,缓存对象中的值。
2、Angular中的$cacheFactory的方法:
<!DOCTYPE html>
<html ng-app="mk">
<head>
<meta charset="UTF-8">
<title>directive</title>
//先引入angular的插件
<script src="angular.min.js"></script>
<script>
var app = angular.module('mk', []);
app.controller('ctrl',function($scope,$cacheFactory){
var cache = $cacheFactory('myCache',{capacity:2});
cache.put('name','ross');
cache.put('age','20');
cache.put('sex','women');
console.log(cache.get('age'));
})
</script>
</head>
<body ng-controller='ctrl'>
</body>
</html>