aboutsummaryrefslogtreecommitdiffstats
path: root/src/service/xhr.cache.js
diff options
context:
space:
mode:
authorIgor Minar2011-03-30 09:35:59 -0700
committerIgor Minar2011-03-30 15:22:22 -0700
commitc06c5a36b108c6ad20776923d75eb6f32ace591b (patch)
treee9a7e52b37702f175cb01aaefd0955c06a8d6be8 /src/service/xhr.cache.js
parent9985104dc0a2f96b1b318a8b662c0806a96f312b (diff)
downloadangular.js-c06c5a36b108c6ad20776923d75eb6f32ace591b.tar.bz2
make xhr.cache optionally synchronous
- add `sync` flag xhr.cache - change ng:include to use the sync flag - change ng:view to use the sync flag The end result is that there are fewer repaints in the browser, which means less "blinking" that user sees.
Diffstat (limited to 'src/service/xhr.cache.js')
-rw-r--r--src/service/xhr.cache.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/service/xhr.cache.js b/src/service/xhr.cache.js
index 284321d7..c6066a5c 100644
--- a/src/service/xhr.cache.js
+++ b/src/service/xhr.cache.js
@@ -20,10 +20,11 @@
* @param {boolean=} [verifyCache=false] If `true` then a result is immediately returned from cache
* (if present) while a request is sent to the server for a fresh response that will update the
* cached entry. The `callback` function will be called when the response is received.
+ * @param {boolean=} [sync=false] in case of cache hit execute `callback` synchronously.
*/
angularServiceInject('$xhr.cache', function($xhr, $defer, $log){
var inflight = {}, self = this;
- function cache(method, url, post, callback, verifyCache){
+ function cache(method, url, post, callback, verifyCache, sync){
if (isFunction(post)) {
callback = post;
post = null;
@@ -31,7 +32,13 @@ angularServiceInject('$xhr.cache', function($xhr, $defer, $log){
if (method == 'GET') {
var data, dataCached;
if (dataCached = cache.data[url]) {
- $defer(function() { callback(200, copy(dataCached.value)); });
+
+ if (sync) {
+ callback(200, copy(dataCached.value));
+ } else {
+ $defer(function() { callback(200, copy(dataCached.value)); });
+ }
+
if (!verifyCache)
return;
}