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

@schafevormfenster/caching

v0.1.1

Published

Unified cache configuration types and helpers

Readme

@schafevormfenster/caching

Unified caching configuration for REST APIs and Next.js applications with semantic cache categories, environment-based overrides, and CDN-friendly headers.

Purpose

Caching is critical for API performance, but managing cache configurations across multiple endpoints can be error-prone and inconsistent. This package provides:

  • Single Source of Truth: Define cache TTLs once, use everywhere
  • Semantic Categories: Name cache strategies by purpose, not duration
  • Environment Flexibility: Override cache settings per environment without code changes
  • CDN-Ready: Automatic Cache-Control and CDN-Cache-Control headers
  • Type Safety: Runtime validation with Zod schemas
  • Next.js Integration: Works seamlessly with Next.js cacheLife config

Installation

pnpm add @schafevormfenster/caching

Cache Categories

Each category represents a different caching strategy optimized for specific content types:

| Category | Use Case | Default Stale | Default Revalidate | Default Expire | |----------|----------|--------------|-------------------|----------------| | auth | Authentication tokens, sessions | 50 minutes | 5 minutes | 1 hour | | static | Static content, rarely changing data | 24 hours | 7 days | 7 days | | dynamic | Dynamic data, moderate change frequency | 4 hours | 1 day | 1 day | | config | Configuration, metadata, OpenAPI specs | 5 minutes | 1 hour | 1 hour | | health | Health checks, real-time status | 10 seconds | 0 (none) | 30 seconds | | error | Error responses | 1 second | 0 (none) | 2 seconds |

Cache Strategy

Each cache category follows a three-tier strategy:

  1. Stale Time: How long content is considered fresh and served immediately
  2. Revalidate Time: Background revalidation interval for stale content
  3. Expire Time: Absolute expiration time (used for stale-if-error)

Basic Usage

Simple Endpoint with Caching

import { getCacheHeaders } from "@schafevormfenster/caching";

export async function GET() {
  const data = await fetchData();
  
  return Response.json(data, {
    headers: getCacheHeaders('dynamic'),
  });
}

Get Cache TTL

import { getCacheTTL } from "@schafevormfenster/caching";

const ttl = getCacheTTL('static');
console.log(ttl); // 86400 (24 hours)

Custom Cache Configuration

import { buildCacheControlHeader } from "@schafevormfenster/caching";

const customConfig = {
  stale: 1800,      // 30 minutes
  revalidate: 3600, // 1 hour
  expire: 7200,     // 2 hours
};

const header = buildCacheControlHeader(customConfig);

API Reference

Functions

  • getCacheHeaders(category) - Returns Cache-Control and CDN-Cache-Control headers
  • getCacheTTL(category) - Returns the stale value in seconds
  • getCacheControlHeader(category) - Returns Cache-Control header string
  • buildCacheControlHeader(config) - Build custom cache control header
  • getCacheConfig(category) - Get full cache configuration with environment overrides
  • getFetchCacheOptions(category, tags?) - Get Next.js fetch cache options

Types

  • CacheCategory - Union type of all cache categories
  • CacheLifeConfig - Cache configuration interface
  • CacheLifeConfigSchema - Zod schema for validation
  • CacheCategorySchema - Zod schema for category validation

Environment Configuration

Override cache settings per environment using environment variables:

# Development: shorter caches for faster iteration
CACHE_DYNAMIC_STALE=300       # 5 minutes instead of 4 hours
CACHE_STATIC_STALE=600        # 10 minutes instead of 24 hours

Pattern: CACHE_{CATEGORY}_{PROPERTY} where:

  • {CATEGORY} is uppercase (AUTH, STATIC, DYNAMIC, CONFIG, HEALTH, ERROR)
  • {PROPERTY} is STALE, REVALIDATE, or EXPIRE

Documentation

License

MIT