🎉 1.3.0 is out! It features the new keyExpirationStrategy option for the redis-strings Handler!
Remote HTTP server with LRU cache

@neshca/server example

Setup and run @neshca/server

To install the @neshca/server package and its peer dependencies, run the following command:

npm i -D @neshca/server pino fastify pino-pretty

Run the server with the following command:

PORT=8080 HOST=localhost npx next-cache-server
Ensure that the @neshca/server is running when you build your Next.js app.

Configure Next.js to use the server:

In this example, we assume that in your deployment, you have REMOTE_CACHE_SERVER_BASE_URL environment variable set to the URL of your @neshca/server. You can use any other way to set the URL.

Create a file called cache-handler.mjs next to your next.config.js with the following contents:

cache-handler.mjs
import { CacheHandler } from '@neshca/cache-handler';
import createServerHandler from '@neshca/cache-handler/server';
 
const baseUrl = process.env.REMOTE_CACHE_SERVER_BASE_URL ?? 'http://localhost:8080';
 
CacheHandler.onCreation(() => {
  const httpHandler = createServerHandler({
    baseUrl,
  });
 
  return {
    handlers: [httpHandler],
  };
});
 
export default CacheHandler;