Home  >  Article  >  Web Front-end  >  A simple JavaScript data caching system implementation code_javascript skills

A simple JavaScript data caching system implementation code_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:17:541030browse
复制代码 代码如下:

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;
}
};
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn