【发布时间】:2019-02-03 15:48:53
【问题描述】:
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(),
}),
});
当我查看非 redis 的示例时,它指出这是一个简单的 { get, set } 用于缓存。这意味着我理论上应该能够做到。
cache : {
get : function() {
console.log("GET!");
},
set : function() {
console.log("SET!");
}
}
无论我尝试什么,当我使用 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 中实现基本缓存的示例?
【问题讨论】:
-
你有 Redis 服务器吗?为了能够提供 chached 响应,您将需要
Redis Server或memcached server,因为包需要 localhost 或host: 'redis-server'上的另一台服务器上的主机 IP 地址,其中 redis-server 是 IP 地址。 -
请将答案标记为已接受
标签: graphql apollo apollo-server