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

@api-craft/cache

v1.0.1

Published

Unified caching middleware for Express.js supporting memory, Redis, and Memcached stores. Part of the API Craft ecosystem.

Readme

@api-craft/cache

Unified caching middleware for Express.js supporting in-memory, Redis, and Memcached cache stores.
Part of the API Craft ecosystem.


Features

  • Cache all GET requests automatically with minimal setup
  • Support for multiple backends:
    • In-memory (default, simple & fast for single server or dev)
    • Redis (recommended for production & distributed caching)
    • Memcached (high-performance distributed caching)
  • Flexible configuration with TTL, route prefix filtering, and exclusions
  • Automatic X-Cache response headers to help debugging cache hits/misses

Installation

pnpm add @api-craft/cache

or with npm

npm install @api-craft/cache

Note: redis and memcached clients are dependencies installed automatically.

Usage

import express from 'express';
import cacheMiddleware from '@api-craft/cache';

const app = express();

app.use(cacheMiddleware({
  storeType: 'redis', // 'memory' | 'redis' | 'memcached'
  ttlSeconds: 120,    // Cache time-to-live in seconds
  prefix: '/api/',    // Only cache routes starting with '/api/'
  exclude: ['/api/auth'], // Exclude these route substrings from caching
  redisOptions: {
    url: 'redis://localhost:6379'
  },
  // memcachedServers: 'localhost:11211' // For Memcached store
}));

app.get('/api/data', (req, res) => {
  // Simulate slow operation
  setTimeout(() => {
    res.json({ message: 'Hello from cached endpoint', time: new Date() });
  }, 1000);
});

app.listen(3000, () => {
  console.log('Server listening on http://localhost:3000');
});

Configuration Options

| Option | Type | Default | Description | | ------------------ | ---------------------------------------- | ------------------- | ---------------------------------------------------------------------------------------- | | storeType | 'memory' | 'redis' | 'memcached' | 'memory' | Cache backend to use. | | ttlSeconds | number | 60 | Cache expiration time in seconds. | | exclude | string[] | [] | Array of URL substrings to exclude from caching. | | prefix | string | '' | Cache only routes starting with this prefix. | | redisOptions | Object | {} | Options for Redis client (see node-redis) | | memcachedServers | string | string[] | 'localhost:11211' | Memcached server(s) address(es). |

Response Headers

X-Cache: HIT — Response served from cache

X-Cache: MISS — Response generated fresh and cached

Notes

  • Redis and Memcached clients are bundled as dependencies and installed automatically.

  • Memcached does not support authentication by default.

  • In-memory caching is suitable for development or single-server environments.

  • For production, Redis or Memcached is recommended for distributed caching.

  • Only caches GET requests by default.

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check issues page.

License

MIT © 2025 Thamilselven

Links