Skip to content

Commit be21bb7

Browse files
kzysTurbo87
authored andcommitted
Handle query parameters correctly
The options parameter is used to represent query parameters. So it must be included to differentiate URLs with different query parameters.
1 parent 2397c53 commit be21bb7

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

app/adapters/application.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ export default RESTAdapter.extend({
1010

1111
ajax: function(url, type, options) {
1212
if (type === 'GET') {
13-
let cache = this.fetcher.get(url);
13+
let cache = this.fetcher.get(url, options);
1414
if (cache) {
1515
return cache;
1616
}
1717
}
1818

1919
return this._super(url, type, options).then(resp => {
20-
this.fetcher.put(url, resp);
20+
this.fetcher.put(url, options, resp);
2121
return resp;
2222
});
2323
},

app/services/fetcher.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,26 @@ const KEY = 'ajax-cache';
77
export default class FetcherService extends Service {
88
@service fastboot;
99

10-
get(url) {
10+
get(url, options) {
1111
let shoebox = this.fastboot.shoebox;
1212
if (!shoebox) {
1313
return;
1414
}
1515
let cache = shoebox.retrieve(KEY) || {};
16-
return cache[url];
16+
let key = cacheKey(url, options);
17+
return cache[key];
1718
}
1819

19-
put(url, obj) {
20+
put(url, options, obj) {
2021
let fastboot = this.fastboot;
2122
let shoebox = this.fastboot.shoebox;
2223
if (!(shoebox && fastboot.isFastBoot)) {
2324
return;
2425
}
2526

2627
let cache = shoebox.retrieve(KEY) || {};
27-
cache[url] = deepCopy(obj);
28+
let key = cacheKey(url, options);
29+
cache[key] = deepCopy(obj);
2830
shoebox.put(KEY, cache);
2931
}
3032

@@ -41,6 +43,10 @@ export default class FetcherService extends Service {
4143
}
4244
}
4345

46+
function cacheKey(url, options) {
47+
return url + JSON.stringify(options);
48+
}
49+
4450
function deepCopy(obj) {
4551
return JSON.parse(JSON.stringify(obj));
4652
}

0 commit comments

Comments
 (0)