in Education by
The apollo basic example at https://www.apollographql.com/docs/apollo-server/features/data-sources.html#Implementing-your-own-cache-backend they state that doing a redis cache is as simple as: 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(), }), }); When I look at the examples of non-redis, it states that it's a simple { get, set } for cache. This means I should theoretically be able to do. cache : { get : function() { console.log("GET!"); }, set : function() { console.log("SET!"); } } No matter what I try, my cache functions are never called when I'm utilizing the graphQL explorer that apollo-server provides natively. I have tried with cacheControl : true and with cacheControl set like it is in https://medium.com/brikl-engineering/serverless-graphql-cached-in-redis-with-apollo-server-2-0-f491695cac7f . Nothing. Is there an example of how to implement basic caching in Apollo that does not utilize the paid Apollo Engine system? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You can look at the implementation of this package which caches the full response to implement your own cache. import { RedisCache } from "apollo-server-redis"; import responseCachePlugin from "apollo-server-plugin-response-cache"; const server = new ApolloServer({ ... plugins: [responseCachePlugin()], cache: new RedisCache({ connectTimeout: 5000, reconnectOnError: function(err) { Logger.error("Reconnect on error", err); const targetError = "READONLY"; if (err.message.slice(0, targetError.length) === targetError) { // Only reconnect when the error starts with "READONLY" return true; } }, retryStrategy: function(times) { Logger.error("Redis Retry", times); if (times >= 3) { return undefined; } return Math.min(times * 50, 2000); }, socket_keepalive: false, host: "localhost", port: 6379, password: "test" }), });

Related questions

0 votes
    I am trying to fetch some data from the GitHub GraphQL but I get a GaphQLError. I have tried the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 19, 2022 in Education by JackTerrance
0 votes
    We have db collection which is little complicated. Many of our keys are JSON objects where fields aren't ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 11, 2022 in Education by JackTerrance
0 votes
    I've been trying to send a cookie back to the client from the server. I get the response data ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    Which among the below directives belonging to the Cache-Control header of HTTP response provide information to the server that the ... -revalidate 3. no-cache 4. None of the above...
asked Jun 24, 2021 in Technology by JackTerrance
0 votes
    Which directive of Cache Control Header of HTTP response provides indication to server to revalidate resource if max-age has passed?...
asked Nov 7, 2020 in Technology by JackTerrance
0 votes
    Which directive of Cache Control Header of HTTP response indicates that resource is cachable by only client and server, no intermediary can cache the resource?...
asked Nov 7, 2020 in Technology by JackTerrance
0 votes
    guys, I've been developing an iphone web application for a while, and encountered a weird problem: when ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    While using a Write Back cache, which of the following policies needs to be abided? (i)No Write Allocate (ii)Write Allocate (iii)Write Around (iv)Write Through...
asked Oct 7, 2020 in Technology by JackTerrance
0 votes
    I am learning about OAuth2 and OpenID Connect by experimenting with ASP.NET Core and IdentityServer4. So far ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 21, 2022 in Education by JackTerrance
0 votes
    I want to send files asynchronously. I got on sending a file client->server->another client, but if ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I want to send files asynchronously. I got on sending a file client->server->another client, but if ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    I want to build my js/css code, write it on disk and serve it using webpack-dev-server in a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I am using jersey, and I want to send (in a POST) a list of objects to the server. This is ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I have a WCF service which is called in 4 different places in my system. It returns approx 500 ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    User visits subdomain1.mydomain.com, which sends back cache-control (public, max-age=86400) instructions in ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
...