Nuc*_*eon 5 apollo graphql apollo-server
https://www.apollographql.com/docs/apollo-server/features/data-sources.html#Implementing-your-own-cache-backend 上的 apollo 基本示例,他们指出进行 redis 缓存非常简单:
const { RedisCache } = require('apollo-server-cache-redis');
const server = new ApolloServer({
typeDefs,
resolvers,
cache: new RedisCache({
host: 'redis-server',
// Options are passed through to the Redis client
}),
dataSources: () => ({
moviesAPI: new MoviesAPI(),
}),
});
Run Code Online (Sandbox Code Playgroud)
当我查看非 redis 的示例时,它指出它是一个简单{ get, set }的缓存。这意味着我理论上应该能够做到。
cache : {
get : function() {
console.log("GET!");
},
set : function() {
console.log("SET!");
}
}
Run Code Online (Sandbox Code Playgroud)
无论我尝试什么,当我使用 apollo-server 原生提供的 graphQL 资源管理器时,我的缓存函数永远不会被调用。
我已经尝试过使用cacheControl : true和cacheControl设置,就像在https://medium.com/brikl-engineering/serverless-graphql-cached-in-redis-with-apollo-server-2-0-f491695cac7f 中一样。没有。
是否有示例说明如何在不使用付费 Apollo Engine 系统的 Apollo 中实现基本缓存?
| 归档时间: |
|
| 查看次数: |
3944 次 |
| 最近记录: |