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

@typepurify/cache

v0.5.10

Published

Simple in-memory REST API cache.

Downloads

1,952

Readme


npm version

🚀 Overview

@typepurify/cache is a lightweight, zero-dependency caching mechanism designed for REST APIs and expensive computational functions. It supports exact TTL (Time To Live), manual invalidation, and maximum capacity (LRU).

📦 Installation

npm install @typepurify/cache

🛠 Features & Examples

1. MemoryCache

import { MemoryCache } from '@typepurify/cache';

// Create a cache with a max size of 1000 items and a global TTL of 60 seconds
const cache = new MemoryCache<string>({
  maxSize: 1000,
  ttl: 60000,
});

// Set data
cache.set('user:123', 'Alice');

// Retrieve data
const user = cache.get('user:123'); // "Alice"

// Check if data exists
if (cache.has('user:123')) {
  // ...
}

// Delete specific key
cache.delete('user:123');

// Clear entire cache
cache.clear();

2. Override TTL on set

You can override the global TTL for specific, highly volatile items.

// Expires in 5 seconds instead of the global TTL
cache.set('crypto:price', '$42,000', { ttl: 5000 });

3. Check for Keys Without Mutating

Use the has method to verify if a key exists without mutating the LRU access order.

if (cache.has('my-key')) {
  // Key exists and is valid
}

4. SlidingWindowCache

Extends item TTL on every successful read access. Query total cached items via .size().

import { SlidingWindowCache } from '@typepurify/cache';

const windowCache = new SlidingWindowCache<string, number>(5000);
windowCache.set('session:1', 100);
console.log(windowCache.size()); // 1

🆕 New in v0.5.8

createStaleWhileRevalidateCache(ttlMs) — SWR Cache

Returns stale data immediately while revalidating in the background after TTL expires.

import { createStaleWhileRevalidateCache } from '@typepurify/cache';

const swr = createStaleWhileRevalidateCache(30_000); // 30s TTL
const data = await swr('user:123', () => fetchUser(123));

BloomFilterCache — Probabilistic Membership Filter

Set-backed bloom filter to prevent redundant cache lookups.

import { BloomFilterCache } from '@typepurify/cache';

const bf = new BloomFilterCache();
bf.add('seen-key');
bf.mightContain('seen-key'); // true
bf.mightContain('unseen'); // false

🛡️ License

MIT © Vallarasu Kanthasamy


📋 Changelog

v0.5.4 — Latest

New Features:

  • FileSystemStorageAdapter — Pluggable async storage adapter for persistent cache backends. Provides getItem, setItem, and removeItem async methods compatible with any key-value storage layer.
import { FileSystemStorageAdapter } from '@typepurify/cache';

const store = new FileSystemStorageAdapter('/tmp/my-cache');
await store.setItem('user:1', { name: 'Alice', age: 30 });
const user = await store.getItem('user:1');
// => { name: 'Alice', age: 30 }
await store.removeItem('user:1');

Bug Fixes:

  • Added prototype pollution guard in Cache.set() — keys matching __proto__, constructor, or prototype are now silently rejected.

v0.5.1

  • Added has(key) method for non-mutating cache existence checks.

0.5.8 Updates

Includes new features.