Skip to content

Instantly share code, notes, and snippets.

@malexsan1
Created April 30, 2017 06:44
Show Gist options
  • Save malexsan1/c5b1b168a80712188bae19c0f18b60df to your computer and use it in GitHub Desktop.
Save malexsan1/c5b1b168a80712188bae19c0f18b60df to your computer and use it in GitHub Desktop.
Redux Persist cache busting
import { AsyncStorage } from 'react-native'
const reducerVersion ='1' //manually change the reducer version to cache bust
const config = {
storage: AsyncStorage
}
const updateReducers = (store) => {
const startup = () => console.log('Do something after local storage has been updated.')
// Check to ensure latest reducer version
AsyncStorage.getItem('reducerVersion').then((localVersion) => {
if (localVersion !== reducerVersion) {
// Purge store
persistStore(store, config, startup).purge()
//save the new reducer version in the local cache
AsyncStorage.setItem('reducerVersion', reducerVersion)
} else {
persistStore(store, config, startup)
}
}).catch(() => {
persistStore(store, config, startup)
AsyncStorage.setItem('reducerVersion', reducerVersion)
})
}
export {
updateReducers
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment