首页 > 编程 > JavaScript > 正文

一个简单的JavaScript数据缓存系统实现代码

2019-11-21 00:10:59
字体:
来源:转载
供稿:网友
复制代码 代码如下:

var DataCache = function(){
if(!(this instanceof DataCache)){
return new DataCache();
}
this.id = 0;
this.caches = {};
};
DataCache.prototype = {
add : function(val){
val = val || null;
key = "dc_" + this.id;

this.caches[key] = val;
return key;
},
remove : function(key){
delete this.caches[key];
},
get : function(key){
return this.caches[key];
},
set : function(key,val){
this.caches[key] = val;
}
};
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表