Skip to content

Commit c3be73c

Browse files
committed
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 a369d6e commit c3be73c

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
@@ -6,24 +6,26 @@ const KEY = 'ajax-cache';
66
export default Service.extend({
77
fastboot: service(),
88

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

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

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

@@ -40,6 +42,10 @@ export default Service.extend({
4042
},
4143
});
4244

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

0 commit comments

Comments
 (0)