1
1
import React , { Component } from 'react'
2
2
import { Switch , Route , Redirect } from 'react-router'
3
3
import { Link } from 'react-router-dom'
4
- import { persistCache } from 'apollo-cache-persist'
4
+ import { CachePersistor } from 'apollo-cache-persist'
5
5
6
6
import logo from '../logo.svg'
7
7
import StarCount from './StarCount'
@@ -11,7 +11,7 @@ import CurrentUser from './CurrentUser'
11
11
import Profile from './Profile'
12
12
import Reviews from './Reviews'
13
13
import CurrentTemperature from './CurrentTemperature'
14
- import { cache } from '../lib/apollo'
14
+ import { cache , apollo } from '../lib/apollo'
15
15
16
16
const Book = ( { user } ) => (
17
17
< div >
@@ -23,6 +23,15 @@ const Book = ({ user }) => (
23
23
</ div >
24
24
)
25
25
26
+ const persistor = new CachePersistor ( {
27
+ cache,
28
+ storage : window . localStorage ,
29
+ maxSize : 4500000 , // little less than 5 MB
30
+ debug : true
31
+ } )
32
+
33
+ apollo . onResetStore ( ( ) => persistor . purge ( ) )
34
+
26
35
const cacheHasBeenSaved = ! ! localStorage . getItem ( 'apollo-cache-persist' )
27
36
28
37
class App extends Component {
@@ -31,12 +40,7 @@ class App extends Component {
31
40
}
32
41
33
42
async componentDidMount ( ) {
34
- await persistCache ( {
35
- cache,
36
- storage : window . localStorage ,
37
- maxSize : 4500000 , // little less than 5 MB
38
- debug : true
39
- } )
43
+ await persistor . restore ( )
40
44
41
45
this . setState ( {
42
46
loading : false
0 commit comments