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 🙏

© 2025 – Pkg Stats / Ryan Hefner

biscuit-cache-js

v1.1.3

Published

A lightweight, persistent, reactive browser cache with background refresh and cross-tab sync. Works like a normal cache but supercharged with sticky TTL and offline support.

Readme

🍪 Biscuit.js

Memory-first, persistent, reactive browser cache with background refresh & cross-tab sync.


✨ Features

  • Memory-first – Instant reads from a fast in-memory Map
  • Persistent – Falls back to IndexedDB for reload-safe storage
  • Reactive – Subscribe to updates for live UI state
  • TTL & Auto-Expiry – Data expires automatically after configurable ttl
  • Background Refresh – Optionally re-fetch data before it goes stale
  • Cross-Tab Sync – Stays in sync across browser tabs/windows
  • Tiny & Dependency-free – Pure JavaScript, no React or framework lock-in

📦 Installation

npm install biscuit-cache-js

🚀 Quick Start

import Biscuit from "@martino-kevo/biscuit-js";

async function main() {
  // 1️⃣ Store data with TTL (5 min default)
  await Biscuit.set("user", { id: 1, name: "Martins" });

  // 2️⃣ Retrieve data
  console.log(Biscuit.get("user")); 
  // => { id: 1, name: "Martins" }

  // 3️⃣ Subscribe to updates
  const unsubscribe = Biscuit.subscribe(state => {
    console.log("Updated Biscuit state:", state);
  });

  // 4️⃣ Mutate in-place
  await Biscuit.mutate("user", user => ({ ...user, name: "Kelvin" }));

  // 5️⃣ Remove data
  await Biscuit.remove("user");

  unsubscribe();
}

main();

⏱ TTL + Background Refresh

async function fetchFriends() {
  const res = await fetch("/api/friends");
  return res.json();
}

// Cache with 1 hour TTL + auto-refresh using the fetcher
await Biscuit.set("friends", await fetchFriends(), 3600_000, fetchFriends);

Biscuit will: Serve data instantly from memory Refresh data 10% before TTL expiry in the background Keep all tabs synced automatically

🔄 Cross-Tab Sync

Open two tabs of your app. Updating Biscuit in one tab updates the other automatically.

await Biscuit.set("theme", "dark");
// Other tabs get notified instantly 🎉

🛠 API Reference

| Method | Description | | --------------------------------- | -------------------------------------------------------------- | | set(key, value, ttl?, fetcher?) | Store data with optional TTL (ms) & background refresh fetcher | | get(key, { extend? }) | Retrieve data (optionally extend TTL on read) | | mutate(key, mutator) | Safely update existing value using a mutator function | | remove(key) | Delete a single entry | | clear() | Clear all entries | | subscribe(fn) | Listen for state changes, returns an unsubscribe function |

💡 Why Biscuit?

Think of Biscuit as localStorage + Reactivity + TTL + Background Refresh. It removes the pain of: Manual cache invalidation Re-fetching data too often Keeping multiple tabs in sync Losing data on page reload

📂 Examples

See the examples/ folder for more use cases:

Basic usage + Advance

📜 License

MIT © Martins Kelvin