@@ -37,7 +37,7 @@ export default class Api {
37
37
paramsData [ key ] = value ;
38
38
} ) ;
39
39
40
- const response = await this . _request ( method , path , paramsData , headers , body ) ;
40
+ const response = this . _request ( method , path , paramsData , headers , body ) ;
41
41
42
42
return ( await response . toPromise ( ) ) . data ;
43
43
}
@@ -70,23 +70,28 @@ export default class Api {
70
70
return await this . get ( method , path , params , headers , body ) ;
71
71
}
72
72
73
- const rawUrl = this . baseUrl + path ;
73
+ let cacheKey = this . baseUrl + path ;
74
74
75
- const force = this . lastCacheDuration !== cacheDurationSeconds ;
75
+ if ( params && Object . keys ( params ) . length > 0 ) {
76
+ cacheKey =
77
+ cacheKey +
78
+ ( cacheKey . search ( / \? / ) >= 0 ? '&' : '?' ) +
79
+ params . map ( ( [ k , v ] ) => `${ encodeURIComponent ( k ) } =${ encodeURIComponent ( v ) } ` ) . join ( '&' ) ;
80
+ }
76
81
77
- if ( force ) {
78
- this . cache . del ( rawUrl ) ;
82
+ if ( this . lastCacheDuration !== cacheDurationSeconds ) {
83
+ this . cache . del ( cacheKey ) ;
79
84
}
85
+ this . lastCacheDuration = cacheDurationSeconds ;
80
86
81
- const cachedItem = this . cache . get ( rawUrl ) ;
82
- if ( cachedItem && ! force ) {
87
+ const cachedItem = this . cache . get ( cacheKey ) ;
88
+ if ( cachedItem ) {
83
89
return Promise . resolve ( cachedItem ) ;
84
90
}
85
- this . lastCacheDuration = cacheDurationSeconds ;
86
91
87
92
const result = await this . get ( method , path , params , headers , body ) ;
88
93
89
- this . cache . put ( rawUrl , result , cacheDurationSeconds * 1000 ) ;
94
+ this . cache . put ( cacheKey , result , cacheDurationSeconds * 1000 ) ;
90
95
91
96
return result ;
92
97
}
0 commit comments