我正在尝试在我的应用程序中实现graphQl Flutter包。
https://github.com/zino-app/graphql-flutter
一切都很好,但我对缓存有一些问题。
如果我们运行这个包https://github.com/zino-app/graphql-flutter/tree/master/packages/graphql_flutter/example中的示例,我们可以看到缓存不工作。
在我的应用中,我也不能提高速度,它总是在线获取数据。
此示例中的代码
class GraphQLWidgetScreen extends StatelessWidget {
const GraphQLWidgetScreen() : super();
@override
Widget build(BuildContext context) {
final HttpLink httpLink = HttpLink(
uri: 'https://api.github.com/graphql',
);
final AuthLink authLink = AuthLink(
// ignore: undefined_identifier
getToken: () async => 'Bearer $YOUR_TOKEN',
);
Link link = authLink.concat(httpLink);
if (ENABLE_WEBSOCKETS) {
final WebSocketLink websocketLink = WebSocketLink(
url: 'ws://localhost:8080/ws/graphql',
config: SocketClientConfig(
autoReconnect: true, inactivityTimeout: Duration(seconds: 15)),
);
link = link.concat(websocketLink);
}
final ValueNotifier<GraphQLClient> client = ValueNotifier<GraphQLClient>(
GraphQLClient(
cache: OptimisticCache(
dataIdFromObject: typenameDataIdFromObject,
),
link: link,
),
);
return GraphQLProvider(
client: client,
child: const CacheProvider(
child: MyHomePage(title: 'GraphQL Widget'),
),
);
}
}显示缓存不工作的动画

因此,问题是-实现缓存的正确方式是什么,检查它是如何工作的。
谢谢!
发布于 2020-02-15 01:09:55
这些示例是独立的-因此,它们使用单独的客户端和缓存。这样做的结果是它是re-instantiated every mount。换句话说,每次导航到示例的路由时,都会获得一个新的缓存,因此看不到缓存效果。有关可以查看缓存是否正常工作的更多示例,请参见the starwars example (related github discussion)
https://stackoverflow.com/questions/59526017
复制相似问题