@@ -7,7 +7,7 @@ const inBrowser = typeof window !== 'undefined'
7
7
// context for each request. To allow caching across multiple requests, we need
8
8
// to attach the cache to the process which is shared across all requests.
9
9
const cache = inBrowser
10
- ? createCache ( )
10
+ ? null
11
11
: ( process . __API_CACHE__ || ( process . __API_CACHE__ = createCache ( ) ) )
12
12
13
13
function createCache ( ) {
@@ -44,11 +44,17 @@ function createServerSideAPI () {
44
44
}
45
45
46
46
function fetch ( child ) {
47
- return new Promise ( ( resolve , reject ) => {
48
- api . child ( child ) . once ( 'value' , snapshot => {
49
- resolve ( snapshot . val ( ) )
50
- } , reject )
51
- } )
47
+ if ( cache && cache . has ( child ) ) {
48
+ return Promise . resolve ( cache . get ( child ) )
49
+ } else {
50
+ return new Promise ( ( resolve , reject ) => {
51
+ api . child ( child ) . once ( 'value' , snapshot => {
52
+ const val = snapshot . val ( )
53
+ cache && cache . set ( child , val )
54
+ resolve ( val )
55
+ } , reject )
56
+ } )
57
+ }
52
58
}
53
59
54
60
export function fetchIdsByType ( type ) {
@@ -57,15 +63,8 @@ export function fetchIdsByType (type) {
57
63
: fetch ( `${ type } stories` )
58
64
}
59
65
60
- export function fetchItem ( id , forceRefresh ) {
61
- if ( ! forceRefresh && cache . get ( id ) ) {
62
- return Promise . resolve ( cache . get ( id ) )
63
- } else {
64
- return fetch ( `item/${ id } ` ) . then ( item => {
65
- cache . set ( id , item )
66
- return item
67
- } )
68
- }
66
+ export function fetchItem ( id ) {
67
+ return fetch ( `item/${ id } ` )
69
68
}
70
69
71
70
export function fetchItems ( ids ) {
0 commit comments