Ajaxmanager icon indicating copy to clipboard operation
Ajaxmanager copied to clipboard

Undefined exception when calling clearCache in bad moment

Open novoj opened this issue 13 years ago • 0 comments

Problem is in _createAjax method:

_createAjax: function(id, o, origSuc, origCom){ var that = this; return function(){ if(o.beforeCreate.call(o.context || that, id, o) === false){return;} that.inProgress++; if(that.inProgress === 1){ $.event.trigger(that.name +'AjaxStart'); } if(o.cacheResponse && cache[id]){ if(!cache[id].cacheTTL || cache[id].cacheTTL < 0 || ((new Date().getTime() - cache[id].timestamp) < cache[id].cacheTTL)){ that.requests[id] = {}; //START OF TWEAK var cachedData = cache[id]; //END OF TWEAK setTimeout(function(){ that._success.call(that, o.context || o, origSuc, cachedData._successData, 'success', cachedData, o); that._complete.call(that, o.context || o, origCom, cachedData, 'success', id, o); }, 0); } else { delete cache[id]; } } if(!o.cacheResponse || !cache[id]) { if (o.async) { that.requests[id] = $.ajax(o); } else { $.ajax(o); } } return id; }; }

When calling method clearCache just in time when setTimeout defers funtion invocation I had "undefined" issue with cache[id] because cache was meanwhile cleared. Fix is very easy and is surrounded by commentaries:

//START / END OF TWEAK

novoj avatar Mar 27 '12 16:03 novoj