Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#113 Build URL to determine if request is cached #297

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/loading-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ angular.module('cfp.loadingBarInterceptor', ['cfp.loadingBar'])
* @return {Boolean} retrns true if cached, otherwise false
*/
function isCached(config) {
var cache;
var defaultCache = $cacheFactory.get('$http');
var defaults = $httpProvider.defaults;
var cache,
defaultCache = $cacheFactory.get('$http'),
defaults = $httpProvider.defaults,
url = buildUrl(config.url, config.paramSerializer(config.params));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single variable declaration per line please


// Choose the proper cache source. Borrowed from angular: $http service
if ((config.cache || defaults.cache) && config.cache !== false &&
Expand All @@ -79,7 +80,7 @@ angular.module('cfp.loadingBarInterceptor', ['cfp.loadingBar'])
}

var cached = cache !== undefined ?
cache.get(config.url) !== undefined : false;
cache.get(url) !== undefined : false;

if (config.cached !== undefined && cached !== config.cached) {
return config.cached;
Expand All @@ -88,6 +89,13 @@ angular.module('cfp.loadingBarInterceptor', ['cfp.loadingBar'])
return cached;
}

function buildUrl(url, serializedParams) {
if (serializedParams.length > 0) {
url += ((url.indexOf('?') == -1) ? '?' : '&') + serializedParams;
}
return url;
}


return {
'request': function(config) {
Expand Down