Caching apollo缓存与nuxt中的vue apollo保持一致

Caching apollo缓存与nuxt中的vue apollo保持一致,caching,async-await,nuxt.js,apollo-client,vue-apollo,Caching,Async Await,Nuxt.js,Apollo Client,Vue Apollo,我试图使用阿波罗缓存持久化,但我被文档弄糊涂了: 这是web初始化代码: import { InMemoryCache } from 'apollo-cache-inmemory'; import { persistCache } from 'apollo-cache-persist'; const cache = new InMemoryCache({...}); // await before instantiating ApolloClient, else queries might

我试图使用阿波罗缓存持久化,但我被文档弄糊涂了:

这是web初始化代码:

import { InMemoryCache } from 'apollo-cache-inmemory';
import { persistCache } from 'apollo-cache-persist';

const cache = new InMemoryCache({...});

// await before instantiating ApolloClient, else queries might run before the cache is persisted
await persistCache({
  cache,
  storage: window.localStorage,
});
await persistCache()
抛出了一个错误,我不明白如果没有异步,它将如何工作。我猜我需要把它放进一个插件中,但我也不知道该怎么做


有关Apollo客户端配置的更多信息,请参见另一个问题:。

我在nuxt.js上没有更新

看看
vue apollo
的作者。它正在修改
main.js
,方法是使用
export async function createApp
和beforeApp、afterApp异步回调来包装
new Vue(…)
,以恢复服务器发送的缓存。您只需
vue添加@akryum/ssr
,在考虑合并客户端和服务器缓存的正确方法后,您将找到一个位置,将异步挂钩放入
entry client.js

或者你可以做一些简单的事情:

//vue-apollo.js
从“apollo缓存持久化”导入{persistCache}
导出异步函数willCreateProvider(){
等待持久缓存({cache,storage:window.localStorage})
}
导出函数createProvider(选项={}){}
//main.js
从“/vue apollo”导入{createProvider,willCreateProvider}
willCreateProvider()。然后(()=>{
新Vue({
路由器,
提供程序:createProvider(),
渲染:h=>h(应用程序),
}).$mount(“#应用程序”)
})
中还有
persistCacheSync