🎉 Version 1.9.0 is out! This is the final release supporting Next.js 13.5.1-14.x. The upcoming version 2.0.0 will require Next.js 15.

local-lru Handler

import createLocalHandler from '@neshca/cache-handler/local-lru';
 
// ...
const localHandler = createLocalHandler({
  maxItemsNumber: 10000,
  maxItemSizeBytes: 1024 * 1024 * 500,
});
// ...

The local-lru Handler uses a lru-cache ↗ instance as the cache store. It stores the cache in memory and evicts the least recently used entries when the cache reaches its limits. You can use this Handler as a fallback cache when the shared cache is unavailable.

The local-lru Handler stores the cache in memory. Make sure to set the limits according to your server’s memory capacity.

API

@neshca/cache-handler/local-lru exports a function that creates a new Handler instance for the local-lru Handler.

Parameters

  • options - An object containing the following properties:
    • maxItemsNumber - Optional. Maximum number of items the cache can hold. Defaults to 1000.
    • maxItemSizeBytes - Optional. Maximum size in bytes for each item in the cache. Defaults to 1024 * 1024 * 100 (100 MB).

Return value

A new Handler instance for the local-lru Handler.