🎉 1.6.0 is out! It features synchronous redis-stack Handler creation function!
Built-in Handlers
experimental-redis-cluster

experimental-redis-cluster Handler

import { createCluster } from 'redis';
import createClusterHandler from '@neshca/cache-handler/experimental-redis-cluster';
 
const cluster = createCluster(clusterOptions);
await cluster.connect();
 
const redisHandler = createClusterHandler({
  cluster,
  keyPrefix: 'JSON:',
  timeoutMs: 1000,
  keyExpirationStrategy: 'EXAT',
  sharedTagsKey: '__sharedTags__',
  revalidateTagQuerySize: 100,
});
// ...
⚠️

This Handler is currently experimental and subject to change or removal in future updates without a major version increment. Use with caution.

The experimental-redis-cluster Handler uses the Redis Cluster as the cache store. It is a simple and fast cache handler that is suitable for most applications. This Handler is ideal for applications that require fast and efficient cache management without the need for advanced features like full-text search for custom revalidation strategies.

API

@neshca/cache-handler/experimental-redis-cluster exports a function that creates a new Handler instance for the experimental-redis-cluster Handler.

Parameters

  • options - An object containing the following properties:
    • cluster - A Redis Cluster instance.
    • keyPrefix - Optional. Prefix for all keys, useful for namespacing. Defaults to an empty string.
    • timeoutMs - Optional. Timeout in milliseconds for Redis operations. Defaults to 5000. For disabling timeouts, set it to 0.
    • keyExpirationStrategy - Optional. It allows you to choose the expiration strategy for cache keys. Defaults to EXPRIREAT.
    • sharedTagsKey - Optional. Dedicated key for the internal revalidation process. It must not interfere with cache keys from your application. Defaults to __sharedTags__.
    • revalidateTagQuerySize - Optional. The number of tags in a single query retrieved from Redis when scanning or searching for tags. Defaults to 100.

keyExpirationStrategy

  • 'EXAT': Uses the EXAT option of the SET command to set the expiration time. This is more efficient than EXPIREAT. Requires Redis server 6.2.0 or newer
  • 'EXPIREAT': Uses the EXPIREAT command to set the expiration time. This requires an additional command call. Requires Redis server 4.0.0 or newer.

revalidateTagQuerySize

You can adjust this value to optimize the number of commands sent to Redis when scanning or searching for tags. A higher value will reduce the number of commands sent to Redis, but it will also increase the amount of data transferred over the network. Redis uses TCP and typically has 65,535 bytes as the maximum size of a packet (it can be lower depending on MTU).

Return value

A new Handler instance for the experimental-redis-cluster Handler.