type $cacheFactory.Cache

用于存储和检索数据的缓存对象,主要用于http和scipt指令,用于缓存模板和其他数据。

用法:

index.html

<!DOCTYPE html>
<html ng-app="indexApp">
<head lang="en">
    <meta charset="UTF-8">
    <title>BookStore</title>
</head>
<body  ng-controller="firCtrl">
<div>
    <label>msg:<input ng-model="msg" /></label>
    <label>id:<input ng-model="msg.id" /></label>
    <label>size:<input ng-model="msg.size" /></label>
</div>
<script src="framework/angular.js"></script>
<script src="myJs/cache.js"></script>
<script src="myJs/index.js"></script>
</body>
</html>

index.js

angular.module('indexApp',["superCache"])
    .controller('firCtrl',['$scope', 'smCache' ,function($scope, smCache){
        smCache.put("name","drr");
        smCache.put("how","like");
        $scope.msg = smCache.info();
}]);

cache.js

angular.module('superCache',[])
.factory('smCache',['$cacheFactory',function($cacheFactory){
    return $cacheFactory('ms');
}]);

方法:

put(key, value);

get(key);

remove(key);

remove(key);

destroy();

info(); 返回具有以下属性的对象:id:缓存实例的id,size::缓存实例中保存的条目的数量...在创建缓存时,选项对象中的任何其他属性。

posted @ 2017-06-16 15:12  发福大叔  阅读(198)  评论(0编辑  收藏  举报