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

@hyperttp/cache

v1.1.6

Published

High-performance LRU caching plugin for Hyperttp client

Readme

hyperttp-cache

Русский | English


🌐 Language


Blazing fast, isomorphic cache management and concurrent request deduplication plugin for the high-performance Hyperttp HTTP client. Optimized for Bun and Node.js runtimes.

The plugin seamlessly integrates into the flat HyperCore lifecycle pipeline, protecting your backend from server breakdown (Cache Stampede Protection) and providing smart in-memory storage based on the LRU (Least Recently Used) strategy.


🔥 Key Features

  • 🧠 LRU Strategy with TTL Support: Automatically evicts old entries when reaching limits. With every GET request, the entry age resets (updateAgeOnGet: true), keeping hot data cached in memory.
  • 🚀 In-Flight Deduplication: Concurrent fan-out requests targeting the same URL are grouped into a single network hot path. The response is cloned and distributed to all waiting subscribers simultaneously.
  • 🔄 HTTP Revalidation: Full freshness verification support via ETag (If-None-Match) and Last-Modified (If-Modified-Since). Automatically re-hydrates empty 304 responses with cached data bodies.
  • 🛡️ Fail-Safe Processing: When network processing exceptions occur, the in-flight waiting pool is instantly purged (onError), unblocking immediate subsequent retry attempts.
  • 📊 Core Extension: Automatically injects cache management methods (clearCache) and appends a cacheSize telemetry metric into the core getStats() architecture.

📦 Installation

bun add hyperttp-cache
# or
npm install hyperttp-cache

🚀 Quick Start

Simply import the withCache factory and append it to your client's plugin array. Cache configurations are passed directly within the global options block.

import { createClient } from "@hyperttp/core";
import { withCache } from "hyperttp-cache";

const client = createClient({
  plugins: [withCache()],
  cache: {
    enabled: true,
    ttl: 60_000,       // 1 minute (defaults to 300_000 ms)
    maxSize: 1000,    // Limit to 1000 items (defaults to 500)
    methods: ["GET"], // HTTP methods authorized for downstream caching
  },
});

// 1. The first request goes out to the network and populates the cache
const res1 = await client.get("/api/data");

// 2. Subsequent requests instantly return an isolated clone from the cache
const res2 = await client.get("/api/data");

⚙️ Configuration Options (CacheManagerOptions)

The plugin configuration layer is fully typed and extends the default client option interfaces:

| Parameter | Type | Default | Description | | --- | --- | --- | --- | | cache.enabled | boolean | false | Activation status flag for the caching layer. | | cache.ttl | number | 300_000 (5 min) | Cache entry time-to-live threshold (in milliseconds). | | cache.maxSize | number | 500 | Maximum entries allowed inside the LRU pool before eviction begins. | | cache.methods | Method[] | ["GET"] | Array of HTTP methods authorized for response interception. |


🛠️ Core API Extensions

The plugin extends the global @hyperttp/types interface declarations. The following lifecycle methods become directly accessible via the client core instance:

Purging Cache

// Purge the entire cache system
client.clearCache();

// Evict a specific URL key from the storage
client.clearCache("/api/data");

Telemetry

If your core implementation supports the getStats() routine, the plugin automatically appends the current cache size:

const stats = client.getStats();
console.log(stats.cacheSize); // Outputs the current number of active entries inside the LRU storage

📐 Lifecycle Architecture

The plugin utilizes atomic, decoupled lifecycle hooks instead of overhead-heavy middleware wrappers:

  1. onRequest: Evaluates local key hits inside the CacheManager. If the matching record is fresh and doesn't require validation, it returns a clone, short-circuiting the chain. If a concurrent request to the same URL is active, it hooks into its matching follower Promise. If a partial hit requires validation, it appends conditional headers (If-None-Match / If-Modified-Since).
  2. onResponse: Intercepts successful downstream outputs. Re-hydrates an empty 304 Not Modified status code back into a full 200 OK response by recovering body content from memory. Saves valid 200 ranges containing validation metadata and resolves execution triggers for all waiting In-Flight threads.
  3. onError: In the event of a critical network failure, it instantly flushes matching active tracking task entries from the map to ensure subsequent retries targeting the failed endpoint are never deadlocked.

📄 License

MIT