File tree 2 files changed +12
-6
lines changed
2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -10,14 +10,14 @@ export default RESTAdapter.extend({
10
10
11
11
ajax : function ( url , type , options ) {
12
12
if ( type === 'GET' ) {
13
- let cache = this . fetcher . get ( url ) ;
13
+ let cache = this . fetcher . get ( url , options ) ;
14
14
if ( cache ) {
15
15
return cache ;
16
16
}
17
17
}
18
18
19
19
return this . _super ( url , type , options ) . then ( resp => {
20
- this . fetcher . put ( url , resp ) ;
20
+ this . fetcher . put ( url , options , resp ) ;
21
21
return resp ;
22
22
} ) ;
23
23
} ,
Original file line number Diff line number Diff line change @@ -7,24 +7,26 @@ const KEY = 'ajax-cache';
7
7
export default class FetcherService extends Service {
8
8
@service fastboot ;
9
9
10
- get ( url ) {
10
+ get ( url , options ) {
11
11
let shoebox = this . fastboot . shoebox ;
12
12
if ( ! shoebox ) {
13
13
return ;
14
14
}
15
15
let cache = shoebox . retrieve ( KEY ) || { } ;
16
- return cache [ url ] ;
16
+ let key = cacheKey ( url , options ) ;
17
+ return cache [ key ] ;
17
18
}
18
19
19
- put ( url , obj ) {
20
+ put ( url , options , obj ) {
20
21
let fastboot = this . fastboot ;
21
22
let shoebox = this . fastboot . shoebox ;
22
23
if ( ! ( shoebox && fastboot . isFastBoot ) ) {
23
24
return ;
24
25
}
25
26
26
27
let cache = shoebox . retrieve ( KEY ) || { } ;
27
- cache [ url ] = deepCopy ( obj ) ;
28
+ let key = cacheKey ( url , options ) ;
29
+ cache [ key ] = deepCopy ( obj ) ;
28
30
shoebox . put ( KEY , cache ) ;
29
31
}
30
32
@@ -41,6 +43,10 @@ export default class FetcherService extends Service {
41
43
}
42
44
}
43
45
46
+ function cacheKey ( url , options ) {
47
+ return url + JSON . stringify ( options ) ;
48
+ }
49
+
44
50
function deepCopy ( obj ) {
45
51
return JSON . parse ( JSON . stringify ( obj ) ) ;
46
52
}
You can’t perform that action at this time.
0 commit comments