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

prerender-redis-cache-ng

v1.0.4

Published

Prerender plugin for Redis caching - Next Generation with ES6, comprehensive tests, and auto-reconnection

Readme

prerender-redis-cache-ng

Tests codecov npm version Node.js Version

Next Generation Prerender plugin for Redis caching with modern ES6+, comprehensive tests, and production-ready features.

⚠️ Note: This is a modernized fork of prerender-redis-cache with significant improvements and new features.

✨ What's New (NG)

  • 🚀 ES6+ Refactored: Modern JavaScript with arrow functions, const/let, template literals
  • 🗑️ Cache Invalidation: DELETE requests for single URL and pattern-based deletion
  • 🔄 Auto-Reconnection: Automatic Redis reconnection with exponential backoff
  • SCAN Command: Non-blocking pattern matching (production-safe, no KEYS)
  • 🛡️ Enhanced Error Handling: Graceful degradation, validation, defensive programming
  • Comprehensive Tests: 33+ tests with 75% coverage (real Redis integration tests)
  • 🔧 CI/CD Ready: GitHub Actions + Codecov integration with Redis service
  • 📚 Better Documentation: Testing guide, API examples, development docs
  • 🐛 Bug Fixes: Fixed TTL=0 handling, header validation, JSON parsing errors
  • Fast Tests: 3x faster test execution (~5s) using real Redis

Prerender plugin for Redis caching, to be used with the prerender node application from https://github.com/prerender/prerender.

How it works

This plugin stores pages returned through prerender in a redis instance. Currently, it caches the pages for 1 day then expires them. This can be overridden by specifying the env variable "process.env.PAGE_TTL" in seconds. To never expire you should set the PAGE_TTL variable to 0.

📦 Installation

Install via npm:

npm install prerender-redis-cache-ng --save

🚀 Quick Start

In your prerender server.js:

const prerender = require('prerender');
const server = prerender();

// Use the Redis cache plugin
server.use(require('prerender-redis-cache-ng'));

server.start();

Configuration

By default it will connect to your Redis instance running on localhost and the default redis port with no authentication, and the default database number (normally 0). You can overwrite this by setting the REDISTOGO_URL, REDISCLOUD_URL, REDISGREEN_URL or REDIS_URL (in the format redis://user:password@host:port/databaseNumber). This currently covers all heroku add-ons for Redis to support quick start.

Automatic Reconnection

The plugin includes automatic reconnection logic with exponential backoff:

  • Automatically retries connection on failure (up to 10 attempts)
  • Maximum reconnection period: 1 hour
  • Gracefully bypasses cache when Redis is unavailable
  • All connection events are logged for monitoring

Environment Variables

  • PAGE_TTL: Cache expiration in seconds (default: 86400 = 1 day)
    • Set to 0 for no expiration
    • Invalid values automatically fall back to the default with a warning

Cache Invalidation

The plugin supports cache invalidation via DELETE requests. This allows you to manually clear cached pages when content is updated.

Clear a single URL

Send a DELETE request to the prerender service with the URL to clear:

curl -X DELETE http://localhost:3000/render?url=http://example.com/page

Response:

{
  "message": "Cache cleared successfully",
  "url": "http://example.com/page",
  "deleted": 1
}

Clear multiple URLs with a pattern

Use wildcards (*) to clear multiple URLs at once:

curl -X DELETE http://localhost:3000/render?url=http://example.com/*

This will clear all cached URLs matching the pattern.

Response:

{
  "message": "Cache cleared successfully",
  "pattern": "http://example.com/*",
  "deleted": 15
}

Note: Pattern matching uses Redis SCAN command (non-blocking, production-safe) to efficiently find matching cache entries without blocking the Redis server.

Acknowledgements

Thanks to the following for making branches with changes which were merged with the 0.2.0 release.

Fantastic Prerender team.

@nelsonkopliku

@eddietio

@irnc

Testing

This project includes a comprehensive test suite using Jest with real Redis integration tests for accurate behavior validation.

Prerequisites

Tests require a running Redis server:

# Using Docker (recommended)
docker run -d -p 6379:6379 redis:latest

# Or use your local Redis instance

Run tests

npm test

Run tests with coverage:

npm run test:coverage

Note: Tests use Redis database 15 to avoid conflicts with production data and automatically clean up after each test.

See TESTING.md for detailed testing information.

Changelog

See CHANGELOG.md for version history and detailed changes.

Recent Updates

v1.0.4 (2025-11-07)

  • 🔧 CI/CD: Fixed Jest hanging issue with --forceExit flag
  • 🔧 CI/CD: Added Redis service to publish workflow
  • 🔧 Testing: Added _closeConnection() method for proper cleanup
  • 📦 Consistency: Unified Redis image to valkey/valkey:9-alpine across all workflows

v1.0.3 (2025-11-07)

  • Testing Infrastructure: Migrated from redis-mock to real Redis integration tests
  • 🚀 Performance: 3x faster test execution (~5s vs ~15s)
  • 🐛 Bug Fix: Fixed Redis v5.x SCAN API cursor type (must be string, not number)
  • 🐛 Bug Fix: Fixed async/await handling in DELETE operations
  • 🔧 CI/CD: Added Redis service to GitHub Actions workflow
  • 📦 Dependencies: Removed redis-mock dependency

v1.0.2 (2025-11-07)

  • 🐛 Critical Bug Fix: Fixed Redis 5.x API compatibility (Promise-based API)

v1.0.1 (2025-11-07)

  • 🐛 Critical Bug Fix: Fixed ClientClosedError on startup by moving Redis auth/select to ready event handler

v1.0.0 (2025-01-07)

  • Cache Invalidation: DELETE requests for single URL and pattern-based deletion
  • ES6 Refactoring: Modern JavaScript with arrow functions, const/let, template literals
  • Comprehensive Tests: 33+ tests with 75% coverage
  • CI/CD: GitHub Actions + Codecov integration
  • SCAN Command: Non-blocking pattern matching (production-safe)
  • Enhanced Error Handling: Automatic reconnection, validation, graceful degradation
  • Better Documentation: Testing guide, development docs, API examples

Todo

  • Slightly finer-grain error catching to make sure this plugin doesn't crash prerender for any reason.