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

nextjs-pg-cache

v1.0.4

Published

Nextjs Postgres package to store the prerendered content and pages in postgres database. Optimal for containerized workload

Readme

next-pg-cache

A Next.js handler for caching database queries using PostgreSQL.

This package provides a middleware solution for Next.js applications to leverage PostgreSQL as a caching layer. By caching database query results, you can significantly improve the performance and scalability of your application.

Installation

Install the package using npm:

Bash

npm install nextjs-pg-cache

Usage

1. Install the middleware:

In your next.config.js file, add the following configuration:

JavaScript

module.exports = {
  cacheHandler: require.resolve('nextjs-pg-cache'),
  cacheMaxMemorySize: 0, // Disable in-memory cache (optional)
};

2. (Optional) Create the cache table:

You can optionally create a table in your PostgreSQL database to store the cached data. Run the following SQL script to create the table named nextjs_cache:

SQL

CREATE UNLOGGED TABLE IF NOT EXISTS public.nextjs_cache (
  key character varying COLLATE pg_catalog."default" NOT NULL,
  value jsonb NOT NULL,
  last_modified bigint NOT NULL,
  tags text[] COLLATE pg_catalog."default",
  CONSTRAINT nextjs_cache_pkey PRIMARY KEY (key)
);

3. Caching database queries:

The middleware automatically caches the results of database queries executed within your Next.js application. You don't need to modify your existing code to leverage the cache.

4. Configuration options:

cacheMaxMemorySize (optional): Controls the maximum size (in bytes) of the in-memory cache. Setting it to 0 disables the in-memory cache and relies solely on the PostgreSQL database for caching.

Below are required and optional env

# MANDATORY ENV
POSTGRES_USER=postgres
POSTGRES_PASSWORD=admin
POSTGRES_DBNAME=postgres
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
# OPTIONAL ENV PARAMS
CONNECTION_TIMEOUT_MILLIS= DEFAULT 0,
IDLE_TIMEOUT_MILLIS= DEFAULT 10000,
MAX_CONNECTIONS= DEFAULT 10,
ALLOW_EXIT_ON_IDLE= DEFAULT false,

DB_SSL_ENABLED=true
# IF DB_SSL_ENABLED true
CA_CRT_PATH=<CA_CERT_PATH>
KEY_PATH=<KEY_PATH>
CERT_PATH=<CERT_PATH>

5. Reporting issues:

Please report any issues or feature requests on the GitHub repository:

[Create Issue Here]