Registry / development / tiny-fifo-cache

tiny-fifo-cache

JSON →
library1.0.1jsnpmunverified

Minimalistic FIFO (First-In-First-Out) in-memory cache for Node.js, v1.0.1 (last released 2015; no updates since). Provides simple put and get operations with automatic eviction of oldest items when the cache reaches a user-defined maximum size. No dependencies, no TypeScript types, relies on CommonJS. Unlike more feature-rich caches (e.g., node-cache, lru-cache), this is a single-purpose FIFO cache with no TTL, no events, and no serialization.

npm install tiny-fifo-cache
INSTALL
IMPORT
SIG · TINY-FIFO-CACHE
T
tiny-fifo-cache
developmentjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FIFOCache
const FIFOCache = require('tiny-fifo-cache');
import FIFOCache from 'tiny-fifo-cache';
Package uses CommonJS; default export is the constructor. ESM import may fail unless the environment supports interop.
FIFOCache
import FIFOCache from 'tiny-fifo-cache';
import { FIFOCache } from 'tiny-fifo-cache';
Default export, not a named export. Named import will be undefined.
FIFOCache.prototype.put
cache.put(key, value);
Method to insert a key-value pair. Returns nothing.
FIFOCache.prototype.get
const val = cache.get(key);
Method to retrieve a value by key; returns undefined if not found.

Demonstrates basic put/get and FIFO eviction when exceeding the maximum size of 3 items.

const FIFOCache = require('tiny-fifo-cache'); const maxItems = 3; const cache = new FIFOCache(maxItems); cache.put('a', 1); cache.put('b', 2); cache.put('c', 3); console.log(cache.get('a')); // 1 // Adding a fourth item evicts the oldest cache.put('d', 4); console.log(cache.get('a')); // undefined (evicted) console.log(cache.get('b')); // 2 console.log(cache.get('d')); // 4
Debug
Known issues
gotchaCache is FIFO but eviction only occurs when adding a new item beyond max, not on read or update. Re-putting an existing key only overwrites its value without resetting its position in the eviction queue.
fix
If reorder-on-access needed, use an LRU cache (e.g., lru-cache).
affects: *
gotchaKeys can be any value, including objects and numbers, but are stored by reference (not hashed). Objects used as keys will be compared by reference, not by value.
fix
Use strings or numbers as keys for predictable behavior.
affects: *
deprecatedPackage is unmaintained since 2015; no bug fixes or feature updates.
fix
Consider migrating to actively maintained alternatives (e.g., tiny-lru, node-cache).
affects: 1.0.1
gotchaNo TypeScript type definitions available. Users must create their own .d.ts or use @ts-ignore.
fix
Write a declaration file: declare module 'tiny-fifo-cache' { export default class FIFOCache { constructor(max: number); put(key: any, value: any): void; get(key: any): any; } }
affects: *
Errors
Common errors & fixes
TypeError: FIFOCache is not a constructor
Using ES6 import incorrectly (e.g., import { FIFOCache } from 'tiny-fifo-cache')
fix
Use default import: import FIFOCache from 'tiny-fifo-cache' or CommonJS require.
undefined method 'get'
Creating cache without the 'new' keyword: const cache = FIFOCache(100)
fix
Use new FIFOCache(100).
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
43 hits · last 30 days
node
36
OpenAI (training)
1
Resources
tiny-fifo-cache — npm install tiny-fifo-cache · libregistry