Created
April 9, 2020 00:51
-
-
Save josemarluedke/f811d5b32f1b74165923a50a6d5ccbde to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ApplicationInstance from '@ember/application/instance'; | |
export function initialize(appInstance: ApplicationInstance): void { | |
const fastboot = appInstance.lookup('service:fastboot'); | |
const apolloCache = appInstance.lookup('service:apollo').client.cache; | |
const shoebox = fastboot.get('shoebox'); | |
if (fastboot.get('isFastBoot')) { | |
shoebox.put('apollo-cache', { | |
get cache(): unknown { | |
return apolloCache.extract(); | |
} | |
}); | |
} else { | |
const cacheContents = shoebox.retrieve('apollo-cache'); | |
if (cacheContents && cacheContents.cache) { | |
apolloCache.restore(cacheContents.cache); | |
} | |
} | |
} | |
export default { | |
name: 'apollo-cache-shoebox', | |
initialize | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment