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

cache-light

v1.0.2

Published

Lightweight, high-performance smart cache for Node.js with async function support, TTL, and optional persistence.

Readme

cache-light

Lightweight, high-performance caching library for Node.js with TTL support and async function caching.


Features

  • ⚡ In-memory caching
  • ⏱️ TTL (Time-To-Live) support
  • 🔁 Async function result caching
  • 🧠 Custom cache key generation
  • 🧹 Auto cleanup of expired entries
  • 📦 Zero dependencies
  • 🧩 ES Modules support

Installation

    npm install cache-light

Usage

    import smartCache from 'cache-light';

for basic cache

    smartCache.set('key', 'value', 5000);

    console.log(smartCache.get('key')); // value

    smartCache.del('key');
    smartCache.clear();

for async function cache

    const fetchData = smartCache.cacheAsync(async () => {
        console.log('Fetching data...');
        return { data: 'Hello World' };
    }, { ttl: 10000 }); // cached for 10s

    await fetchData(); // fetches
    await fetchData(); // cached

auto cleanup

    smartCache.enableAutoCleanup(30000);

Example One:

    // Basic cache
    smartCache.set('Hi', 'Glad', 5000);
    console.log(smartCache.get('Glad'));

    // Async function cache
    const fetchData = smartCache.cacheAsync(async id => {
        console.log('Fetching data for', id);
        return { id, data: `Data for ${id}` };
    }, { ttl: 10000 });

    (async () => {
        console.log(await fetchData(1)); // Fetches
        console.log(await fetchData(1)); // Cached
    })();

    // Enable automatic cleanup every 30 seconds
    smartCache.enableAutoCleanup(30000);

Example Two:

    const fetchUsers = smartCache.cacheAsync(async () => {
        console.log('Calling API...');

        const res = await fetch('https://jsonplaceholder.typicode.com/users');
        const data = await res.json();

        return data;
    }, { ttl: 10000 }); // cache for 10 seconds

    // Run multiple times
    async function run() {
        console.log('First call:');
        console.log(await fetchUsers());

        console.log('\nSecond call (should be cached):');
        console.log(await fetchUsers());

        console.log('\nWaiting 11 seconds...');
        setTimeout(async () => {
            console.log('\nThird call (cache expired):');
            console.log(await fetchUsers());
        }, 11000);
    }

    run();

Example Three:

    const fetchUserById = smartCache.cacheAsync(
        async (id) => {
            console.log(`Fetching user ${id}...`);
            const res = await fetch(`https://jsonplaceholder.typicode.com/users/${id}`);
            return res.json();
        },
        {
            ttl: 10000,
            keyGenerator: ([id]) => `user:${id}`
        }
    );

    // Usage
    // API call
    console.log(await fetchUserById(1));
    // from Cache Memory
    console.log(await fetchUserById(1));
    // New API call
    console.log(await fetchUserById(2)); 

API

- set(key, value, ttl)

- Store a value with optional TTL (in ms)

- get(key)

- Retrieve cached value

- del(key)

- Delete a key

- clear()

- Clear entire cache

- cacheAsync(fn, options)

    - Cache async function results

    - Options:

    - ttl > cache duration (ms)

    - keyGenerator > custom key logic

- enableAutoCleanup(interval)

- Automatically removes expired entries

Requirements

- Node.js >= 16
- ES Modules ("type": "module")

License

MIT © [GladsonRouth]