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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@explita/cache

v0.1.0

Published

Powerful hybrid caching library for Node.js with support for Memory and Redis, featuring stampede protection, namespacing, and metrics.

Downloads

71

Readme

@explita/cache

License: MIT

A high-performance, production-ready Hybrid L1/L2 Caching Suite for Node.js. Designed for speed, reliability, and developer experience.

✨ Features

  • 🚀 Hybrid Architecture: Blazing fast Local Memory (L1) fallback to Distributed Redis (L2).
  • 🔄 Stale-While-Revalidate (SWR): Serve stale data instantly while refreshing in the background.
  • 🛡️ Stampede Protection: Prevents "Thundering Herd" by collapsing concurrent duplicate requests.
  • 📡 Event-Driven: Built-in EventEmitter for monitoring hits, misses, expirations, and SWR triggers.
  • 📦 Batch Operations: Atomic-like pipelines for mget, mset, and mdel.
  • 🛠️ Custom Serialization: Plug-in support for SuperJSON, msgpack, or any custom format.
  • 🧹 Pattern Clearing: Efficiently clear keys using glob patterns (e.g., user:*).
  • 🏷️ Tag-Based Invalidation: Group keys with tags and invalidate entire categories at once.
  • 📊 Metrics: Built-in tracking for hits, misses, and set operations.

📦 Installation

pnpm add @explita/cache ioredis
# or
npm install @explita/cache ioredis

Redis Configuration

To enable the Redis (L2) layer, simply install ioredis and set the following environment variables in your .env file:

REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=optional_password

If these variables are present, the cache will automatically attempt to connect to Redis using a default internal client, unless a custom client is provided in the configuration.

🚀 Quick Start

import { createCache } from "@explita/cache";

const cache = createCache("app:", {
  enableL1: true, // Enable local memory cache
  l1TtlSeconds: 60, // L1 TTL (shorter than L2)
});

// Basic usage
await cache.set("users:1", { name: "Explita" }, { ttl: 3600 });
const user = await cache.get("users:1");

// Powerful 'remember' with SWR
const data = await cache.remember(
  "profile:1",
  async () => {
    return await fetchProfileFromDB(1);
  },
  {
    ttl: 60,
    swr: 300, // Return stale data for 5 mins while revalidating
  },
);

🔌 Custom Serialization (Handling Dates, Maps, etc.)

Easily handle complex types using libraries like superjson:

import superjson from "superjson";

const cache = createCache("meta:", {
  serializer: (v) => superjson.stringify(v),
  deserializer: (v) => superjson.parse(v),
});

await cache.set("now", new Date()); // Works perfectly!

🏷️ Tag-Based Invalidation

Group keys together and wipe them out in one go:

// Set data with tags
await cache.set("product:123", { name: "MacBook" }, { tags: ["products"] });
await cache.set("product:456", { name: "iPhone" }, { tags: ["products"] });

// Later, invalidate everything in the 'products' category
await cache.invalidate("products");

📡 Monitoring with Events

cache.on("hit", (key, value) => console.log(`🔥 Hit: ${key}`));
cache.on("miss", (key) => console.log(`❄️ Miss: ${key}`));
cache.on("swr", (key) => console.log(`🔄 Refreshing: ${key}`));
cache.on("expired", (key) => console.log(`💀 Expired: ${key}`));

🗃️ Storage Modules

You can also use the underlying stores standalone if you don't need the orchestrator:

import { createMemoryStore, createRedisStore } from "@explita/cache";

const mem = createMemoryStore({ cleanupIntervalMs: 10000 });
const redisStore = createRedisStore(myRedisClient);

📝 License

MIT © Explita