File tree 2 files changed +36
-8
lines changed
2 files changed +36
-8
lines changed Original file line number Diff line number Diff line change @@ -4,9 +4,24 @@ import { computed } from '@ember/object';
4
4
5
5
export default RESTAdapter . extend ( {
6
6
fastboot : service ( ) ,
7
+ fetcher : service ( ) ,
7
8
8
9
namespace : 'api/v1' ,
9
10
11
+ ajax : function ( url , type , options ) {
12
+ if ( type === 'GET' ) {
13
+ let cache = this . fetcher . get ( url ) ;
14
+ if ( cache ) {
15
+ return cache ;
16
+ }
17
+ }
18
+
19
+ return this . _super ( url , type , options ) . then ( resp => {
20
+ this . fetcher . put ( url , resp ) ;
21
+ return resp ;
22
+ } ) ;
23
+ } ,
24
+
10
25
headers : computed ( 'fastboot.{isFastBoot,request.headers}' , function ( ) {
11
26
if ( this . fastboot . isFastBoot ) {
12
27
return { 'User-Agent' : this . fastboot . request . headers . get ( 'User-Agent' ) } ;
Original file line number Diff line number Diff line change @@ -4,23 +4,36 @@ import ajax from 'ember-fetch/ajax';
4
4
export default Service . extend ( {
5
5
fastboot : service ( ) ,
6
6
7
- ajax ( url ) {
7
+ get ( url ) {
8
+ let shoebox = this . fastboot . shoebox ;
9
+ let cache = shoebox . retrieve ( 'ajax-cache' ) ;
10
+ if ( ! cache ) {
11
+ cache = { } ;
12
+ }
13
+ return cache [ url ] ;
14
+ } ,
15
+
16
+ put ( url , obj ) {
8
17
let fastboot = this . fastboot ;
9
18
let shoebox = this . fastboot . shoebox ;
10
19
let cache = shoebox . retrieve ( 'ajax-cache' ) ;
11
20
if ( ! cache ) {
12
21
cache = { } ;
13
22
}
23
+ if ( shoebox && fastboot . isFastBoot ) {
24
+ cache [ url ] = deepCopy ( obj ) ;
25
+ shoebox . put ( 'ajax-cache' , cache ) ;
26
+ }
27
+ } ,
14
28
15
- if ( cache [ url ] ) {
16
- return cache [ url ] ;
29
+ ajax ( url ) {
30
+ let resp = this . get ( url ) ;
31
+ if ( resp ) {
32
+ return resp ;
17
33
}
18
34
19
- return ajax ( url ) . then ( function ( resp ) {
20
- if ( shoebox && fastboot . isFastBoot ) {
21
- cache [ url ] = deepCopy ( resp ) ;
22
- shoebox . put ( 'ajax-cache' , cache ) ;
23
- }
35
+ return ajax ( url ) . then ( resp => {
36
+ this . put ( url , resp ) ;
24
37
return resp ;
25
38
} ) ;
26
39
} ,
You can’t perform that action at this time.
0 commit comments