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

flexi-cache-node

v1.0.2

Published

Node.js cache with TTL/LRU, tags, disk persistence, AES-GCM encryption.

Readme

flexi-cache-node

⚡ Next-gen caching library for Node.js with TTL, LRU eviction, tag support, disk persistence, and AES-256-GCM encryption.
A modern replacement for node-cache.


✨ Features

  • 🕒 TTL (Time-to-Live) — per-key or global, with auto-expire sweeps
  • 📝 Version history — keep N previous values per key
  • 🏷️ TagCache — group keys by tags, bulk get/delete via tags
  • ♻️ LRUCache — automatic eviction of least-recently used keys
  • 💾 Persistence — save/load cache to disk (atomic, crash-safe)
  • 🔒 AES-256-GCM encryption — optional at-rest encryption for persisted data
  • 📊 Stats & events — hit/miss counts, set/expired/del/clear events
  • 🔧 TypeScript first — full typings included
  • 🔌 Pluggable backends (future: S3, GCP, Azure)

📦 Installation

npm install flexi-cache-node
# or
yarn add flexi-cache-node

🚀 Quick Start

NodeCache (basic in-memory cache with TTL)

const NodeCache = require("flexi-cache-node");

const cache = new NodeCache({ stdTTL: 5 }); // default TTL = 5s
cache.set("foo", "bar");

console.log(cache.get("foo")); // "bar"

setTimeout(() => {
  console.log(cache.get("foo")); // undefined (expired)
}, 6000);

TagCache (organize keys by tags)

const { TagCache } = require("flexi-cache-node");

const tc = new TagCache();
tc.setWithTags("user:1", { name: "Alice" }, ["active", "premium"]);
tc.setWithTags("user:2", { name: "Bob" }, ["active"]);

console.log(tc.getValuesByTag("active"));
// → [ { name: "Alice" }, { name: "Bob" } ]

tc.deleteTag("premium"); // bulk remove premium users

LRUCache (size-bounded with eviction)

const { LRUCache } = require("flexi-cache-node");

const lru = new LRUCache({ size: 2 });

lru.set("a", 1);
lru.set("b", 2);
lru.get("a");   // mark a as recently used
lru.set("c", 3); // evicts "b"

console.log(lru.getKeys()); // [ 'a', 'c' ]

Persistence (with AES-GCM encryption)

const NodeCache = require("flexi-cache-node");

const cache = new NodeCache({
  stdTTL: 0,
  encryption: true,
  secretKey: process.env.CACHE_SECRET || "superSecretKey123",
  persistPathFolder: {
    type: "disk",
    diskConfig: { folderLocation: "./cache-data" }
  }
});

cache.set("sessionToken", { id: 123, scope: ["read", "write"] });
await cache.flush(); // save to disk (encrypted)

⚙️ Options

| Option | Type | Default | Description | |--------------------|----------|--------------------------|-------------| | size | number | 10000 | Max entries (for LRU/size check) | | stdTTL | number | 0 | Default TTL in seconds (0 = no TTL) | | deleteOnExpire | boolean | true if TTL>0 | Auto-delete expired entries | | versionHistory | number | 3 | How many old values to keep | | checkperiod | number | 600 | Expiration sweep interval (sec) | | backup | boolean | true | Auto-persist on sweeps | | persistPathFolder| object | { type: "disk", ... } | Persistence config (currently disk only) | | encryption | boolean | false | Enable AES-256-GCM encryption | | secretKey | string | "" | Required if encryption = true |


🔔 Events

cache.on("set", (key, value) => { ... });
cache.on("del", (key) => { ... });
cache.on("clear", () => { ... });
cache.on("expired", (key, value) => { ... });

📊 Stats

console.log(cache.getStats());
// { hits: 2, misses: 1, keys: 5 }

📂 Examples

See examples/ in the repo for 3 JS and 3 TS usage demos:

  • NodeCache basic
  • TagCache tags
  • LRUCache eviction
  • Persistence with/without encryption

🔐 Security Notes

  • Use a strong, random secretKey (≥ 32 chars recommended).
  • Never commit keys in code; load from environment variables or a vault.
  • Encrypted persistence format: [IV(12) | TAG(16) | ciphertext].

🛠 Roadmap

  • [ ] Pluggable backends: S3, GCP, Azure
  • [ ] In-memory + distributed hybrid
  • [ ] Compression for large values

🤝 Contributing

Issues and PRs welcome!
Check out GitHub Issues.


📜 License

MIT © 2025 Subhadip