代码拉取完成,页面将自动刷新
/**
* @name Smarge
* @author crazymus < QQ:291445576 >
* @des A cache framework base on HTML5 localstorage.
* @version 1.0.0
* @Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
* @updated 2015-08-10
*/
var Smarge = {
db:'SMARGE0',
use:function(index){
if(index<0 || index>16){
console.log('warning:0-16 is legal.');
return ;
}
this.db = 'SMARGE'+index;
},
set:function(key,value,expire){
var data;
if(localStorage[this.db]){
data = JSON.parse(localStorage[this.db]);
}else{
data = {};
}
var d = new Date();
var obj = {
value:JSON.stringify(value),
time:(d.getTime()/1000).toFixed(0),
expire:expire?expire:0
};
data[key] = obj;
localStorage[this.db] = JSON.stringify(data);
},
get:function(key){
var data;
if(localStorage[this.db]){
data = JSON.parse(localStorage[this.db]);
}else{
return undefined;
}
if(!data[key]){
return undefined;
}
var obj = data[key];
if(obj.expire>0){
//检查过期时间
if(this._getTime() - obj.time > obj.expire){
data[key] = undefined;
localStorage[this.db] = JSON.stringify(data);
return undefined;
}
}
return JSON.parse(data[key].value);
},
drop:function(index){
localStorage['SMARGE'+index] = "";
},
//获取当前时间戳
_getTime:function(){
var d = new Date();
return (d.getTime()/1000).toFixed(0);
}
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。