Repository for implementing caching solutions in Next.js, React Router and other frameworks. This monorepo contains cache handlers and utilities designed to provide efficient and scalable caching.
@nimpl/cache is a cache solutions library for creating universal cache-handlers. The library provides building blocks including core handlers (caching strategies) and cache layers (specific cache sources like in-memory LRU or Redis).
@nimpl/cache-redis is a showcase library that demonstrates how to build a cache handler using @nimpl/cache. It implements a two-tier caching strategy: an in-memory LRU cache for fast local access and Redis for shared cache across multiple pods.
Read more about @nimpl/cache-redis
Install the core library:
npm install @nimpl/cache
# or
pnpm add @nimpl/cacheCreate your custom cache handler:
// cache-handlers/default.js
import { CacheHandler, LruLayer, FsLayer } from "@nimpl/cache";
export default new CacheHandler({
ephemeralLayer: new LruLayer(),
persistentLayer: new FsLayer(),
});Configure in next.config.ts:
import { type NextConfig } from "next/types";
const nextConfig: NextConfig = {
cacheComponents: true,
cacheHandlers: {
default: import.meta.resolve("./cache-handlers/default.js"),
},
};
export default nextConfig;@nimpl/cache-widget is a React widget for visualizing and inspecting cache entries. It provides a user-friendly interface to view cache keys, their details, and metadata in your application.
Read more about @nimpl/cache-widget
@nimpl/cache-tools provides utilities for working with @nimpl/cache-like cache handlers, including data retrieval and function caching. It offers helpers for creating cached functions and API routes for cache inspection tools like @nimpl/cache-widget.
Read more about @nimpl/cache-tools
Note: The following packages are outdated and not actively maintained for now. They will be updated and improved soon:
@nimpl/cache-adapter- Legacy cache adapter package@nimpl/cache-in-memory- Legacy in-memory cache handlerFor new projects, use
@nimpl/cacheto build custom handlers