From 99f3b70b2d316f5bb39e21249e752c29f49c90ab Mon Sep 17 00:00:00 2001 From: Alexander Shtuchkin Date: Thu, 28 Feb 2013 09:25:21 +0400 Subject: feat(http): set custom default cache in $http.defaults.cache When we need more control over http caching, we may want to provide a custom cache to be used in all http requests by default. To skip default cache, set {cache: false} in request configuration. To use other cache, set {cache: cache} as before. See #2079 --- src/ng/http.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/ng/http.js') diff --git a/src/ng/http.js b/src/ng/http.js index 99c1fff3..e4d695c4 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -306,6 +306,9 @@ function $HttpProvider() { * cache, but the cache is not populated yet, only one request to the server will be made and * the remaining requests will be fulfilled using the response for the first request. * + * A custom default cache built with $cacheFactory can be provided in $http.defaults.cache. + * To skip it, set configuration property `cache` to `false`. + * * * # Response interceptors * @@ -733,8 +736,10 @@ function $HttpProvider() { promise.then(removePendingReq, removePendingReq); - if (config.cache && config.method == 'GET') { - cache = isObject(config.cache) ? config.cache : defaultCache; + if ((config.cache || defaults.cache) && config.cache !== false && config.method == 'GET') { + cache = isObject(config.cache) ? config.cache + : isObject(defaults.cache) ? defaults.cache + : defaultCache; } if (cache) { -- cgit v1.2.3