-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path31-缓存服务.html
48 lines (40 loc) · 1.2 KB
/
31-缓存服务.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>缓存</title>
</head>
<body>
<div ng-controller="test" id="parent" >
</div>
<div ng-controller="test2" id="sibings" >
</div>
<script type="text/javascript" src="js/angular.min.js" ></script>
<script>
var m1 = angular.module('myApp',[]);
m1.controller('test',['$scope','$cacheFactory',function($scope,$cacheFactory){
//缓存信息的设置、获取、删除
/*
var cache = $cacheFactory('myCache');
cache.put('name','hello');
cache.put('age',20);
console.log(cache.info());
cache.remove('name');
console.log(cache.info());
console.log(cache.get('age'));
*/
var myCache = $cacheFactory('myCache1',{capacity:10});//capacity 设置缓存长度
myCache.put('name','hello');
myCache.put('age',20);
myCache.put('job','IT');
console.log(myCache.info());
console.log(myCache.get('age'));
}]);
m1.controller('test2',function($scope,$cacheFactory){
var Cache = $cacheFactory('myCache1',{capacity:10});//capacity 设置缓存长度
console.log(Cache.info());
console.log(Cache.get('age'));
})
</script>
</body>
</html>