diff --git a/source/Ox.UI/js/Core/Request.js b/source/Ox.UI/js/Core/Request.js index 0c47cb63..f3ec3547 100644 --- a/source/Ox.UI/js/Core/Request.js +++ b/source/Ox.UI/js/Core/Request.js @@ -16,6 +16,7 @@ Ox.Request = (function() { requests = {}, self = { options: { + cache: true, timeout: 60000, type: 'POST', url: '/api/' @@ -24,6 +25,17 @@ Ox.Request = (function() { $element; return { + + /*@ + bindEvent Bind event + @*/ + bindEvent: function() { + if (!$element) { + $element = Ox.Element(); + } + $element.bindEvent.apply(this, arguments); + }, + /*@ cancel cancel pending requests () -> cancel all requests @@ -49,6 +61,7 @@ Ox.Request = (function() { requests: Ox.len(requests) }); }, + /*@ clearCache clear cached results () -> ... @@ -63,16 +76,6 @@ Ox.Request = (function() { } }, - /*@ - bindEvent Bind event - @*/ - bindEvent: function() { - if (!$element) { - $element = Ox.Element(); - } - $element.bindEvent.apply(this, arguments); - }, - /*@ options get/set options () -> get options @@ -131,7 +134,7 @@ Ox.Request = (function() { )) { setTimeout(function() { callback(cache[req].data, true); - }, 0); + }); } else { pending[options.id] = true; $.ajax({ @@ -192,10 +195,12 @@ Ox.Request = (function() { if (Ox.contains([200, 404, 409], data.status.code)) { // we have to include not found and conflict // so that handlers can handle these cases - cache[req] = { - data: data, - time: Ox.getTime() - }; + if (self.options.cache) { + cache[req] = { + data: data, + time: Ox.getTime() + }; + } callback(data, true); } else { callback(data, false);