npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@nimpl/cache-widget

v0.2.4

Published

React widget for visualizing and inspecting cache entries from `@nimpl/cache-redis`.

Readme

@nimpl/cache-widget

React widget for visualizing and inspecting cache entries from @nimpl/cache-redis.

Installation

npm install @nimpl/cache-widget @nimpl/cache-tools
# or
pnpm add @nimpl/cache-widget @nimpl/cache-tools

Setup

To connect the widget, you need to add the component and styles to a convenient location (a private route, internal copy of the application, conditional layer for authorized users, specific environment, etc.)

You also need to configure API routes for the widget. /api/cache-widget for getting the list of keys and /api/cache-widget/[slug] for getting data for a specific key. For this purpose, you can use the @nimpl/cache-tools utility.

cache-widget and cache-tools can work with any cache-handler, but for them to work, the cache-handler must have an additional keys() method beyond the standard for getting the list of keys. Solutions from @nimpl/cache are compatible out of the box.

Initialize a cache handler

// cache-handler.ts
import { CacheHandler } from "@nimpl/cache-redis/cache-handler";
import { createCache, createHelpers } from "@nimpl/cache-tools";

const cacheHandler = new CacheHandler({
  redisOptions: { connectionStrategy: "wait-ignore" },
});

export const { cache } = createCache(cacheHandler);
export const { getKeys, getKeyDetails, getCacheData } =
  createHelpers(cacheHandler);

Add an API route for the widget

React Router loader:

// app/api/cache-widget/route.ts
import { getCacheData } from "@/cache-handler";

export const loader = async ({ params }: { params: { id?: string } }) => {
  const data = await getCacheData(params.id ? [params.id] : undefined);

  if (!data) return new Response("", { status: 404 });

  return new Response(JSON.stringify(data));
};

Next.js route handler:

// app/api/cache-widget/[[...segments]]/route.ts
import { getCacheData } from "@/cache-handler";
import cacheHandler from "@nimpl/cache-redis";

export async function GET(
  _request: Request,
  { params }: { params: Promise<{ segments?: string[] }> }
) {
  const { segments } = await params;
  const data = await getCacheData(cacheHandler, segments);

  if (!data) return new Response("", { status: 404 });

  return new Response(JSON.stringify(data));
}

Use getCacheData as the single entry point. This ensures that when the internal API of the widget or cache-tools changes, you won't need to make new changes. The route will automatically continue to support the configured methods.

Add the widget to your layout

Add the CacheWidget component to your root layout or any place:

// app/layout.tsx
import { CacheWidget } from "@nimpl/cache-widget";
import "@nimpl/cache-widget/styles.css";

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html>
      <body>
        {children}
        <CacheWidget />
      </body>
    </html>
  );
}

You can customize the API endpoint URL (default - /api/cache-widget):

<CacheWidget apiUrl="/api/custom-cache-endpoint" />

License

MIT