Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
tower1229 committed Jul 4, 2018
1 parent 53dc9fa commit 8eb34a0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2565,7 +2565,7 @@ <h4>解密数据</h4>
<p>加密接口需要返回3DES加密后的数据字符串,客户端将使用3DES算法解密,并经<code>JSON.parse</code>解析为json格式,返回给回调函数。</p>

<h3 id="solution-ajaxcatch">快照缓存</h3>
<p>为app.ajax配置<code>snapshoot:true</code>即可开启快照缓存,即把每一次成功返回的ajax结果保存为快照,下次发起相同请求(判断依据是url和参数相同)时第一时间将快照取出返回给回调函数,待真实数据返回后校验与快照是否相同(需要数据为json格式),若相同则缓存命中,不同则再次调用回调函数并传入真实数据,为了使业务中能够区分出快照,会为快照数据添加一个'snapshoot'属性值为'true'。</p>
<p>为app.ajax配置<code>snapshoot:true</code>即可开启快照缓存,即把每一次成功返回的ajax结果保存为快照,下次发起相同请求(判断依据是url和参数相同)时第一时间将快照取出返回给回调函数,待真实数据返回后校验与快照是否相同(需要数据为json格式),若相同则缓存命中,会为对象格式的快照数据添加一个'snapshootEqual'属性值为'true',不同则再次调用回调函数并传入真实数据,为了使业务中能够区分出快照,会为快照数据添加一个'snapshoot'属性值为'true'。</p>
<h4>示例</h4>
<pre>
<code>
Expand Down
54 changes: 49 additions & 5 deletions sdk/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,46 @@ var gh=((((ga*ga)>>>17)+ga*gb)>>>15)+gb*gb;var gl=(((gx&4294901760)*gx)|0)+(((gx
break;
}
};
var isEqual = function(o, x) {
if (!o || !x) {
return false;
}
var p;
for (p in o) {
if (typeof(x[p]) == 'undefined') {
return false;
}
}
for (p in o) {
if (o[p]) {
switch (typeof(o[p])) {
case 'object':
if (!isEqual(o[p], x[p])) {
return false;
}
break;
case 'function':
if (typeof(x[p]) == 'undefined' ||
(p != 'equals' && o[p].toString() != x[p].toString()))
return false;
break;
default:
if (o[p] != x[p]) {
return false;
}
}
} else {
if (x[p])
return false;
}
}
for (p in x) {
if (typeof(o[p]) == 'undefined') {
return false;
}
}
return true;
};
var ajaxTag = parseInt(Math.random()*1e6);
var requestAjax = function(config) {
var opt = $.extend({
Expand Down Expand Up @@ -1186,17 +1226,21 @@ var gh=((((ga*ga)>>>17)+ga*gb)>>>15)+gb*gb;var gl=(((gx&4294901760)*gx)|0)+(((gx
var handleRes = function(res, fromSnap) {
if (res) {
//json格式异常处理
if(opt.dataType==="json" && res.data && res.data.split){
if(opt.dataType==="json" && res.split){
try{
res.data = JSON.parse(res.data);
res = JSON.parse(res);
}catch(e){
console.log(e.msg)
}
//快照处理
if(opt.snapshoot && !fromSnap){
if(isEqual(res, app.storage.val(urlkey))){
res.snapshootEqual = true;
}
app.storage.val(urlkey, res);
}
}
//存储快照
if(opt.snapshoot && !fromSnap){
app.storage.val(urlkey, res);
}
typeof(tempSucc)==='function' && tempSucc(res);
}
}
Expand Down

0 comments on commit 8eb34a0

Please sign in to comment.