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::缓存实例中保存的条目的数量...在创建缓存时,选项对象中的任何其他属性。

转载于:https://www.cnblogs.com/ms-grf/p/7027664.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值