Skip to content

How to add caching capabilities #295

@ilijaNL

Description

@ilijaNL

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.5.3

Plugin version

^9.0.0

Node.js version

18

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

macosx

Description

First thanks for this library,

I am trying to create a graphql proxy with caching capabilities. Therefor I am trying to use fastify.addHook('preHandler', ...) to parse the query and possibly retrieve result from cache and fastify.addHook('onSend', ...) to store the cache however I am kind of stuck on storing the cache value from onSend hook. In general, how can cache be implemented inside proxy using fastify-http-proxy?

Steps to Reproduce

fastify.register(async (fastify) => {
   fastify.addHook("preHandler", async (req) => {
      console.log({ body: req.body });
      // retrieve from cache
    });

    fastify.addHook("onSend", async (req, reply, payload) => {
      // payload is BodyReadable
      console.log({ payload: payload });
      // set the cache
    });
    fastify.register(fastifyProxy, {
      upstream: "http://localhost:8082/v1/graphql",
      proxyPayloads: false,
      prefix: "/v1/graphql",
      // undici: {},
      websocket: true,
    });
  });
})

Expected Behavior

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions