Registry / storage / appolo-cache

appolo-cache

JSON →
library8.0.0jsnpmunverified

Appolo Cache is an in-memory LRU cache for Node.js written in TypeScript. The current stable version is 8.0.0. It provides a simple API for caching key-value pairs with optional per-item TTL and automatic eviction of least recently used items when the maximum cache size is reached. Key differentiators include typed generics, built-in maxAge support, and utility methods like peek, pop, and prune. It is lightweight, dependency-free, and well-suited for server-side caching needs.

npm install appolo-cache
INSTALL
IMPORT
SIG · APPOLO-CACHE
A
appolo-cache
storagejavascriptv8.0.0
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.

Cache
import { Cache } from 'appolo-cache'
const Cache = require('appolo-cache')
ESM import with named export. CommonJS require does not work; you must use require('appolo-cache').Cache or destructure.
CacheOptions
import { CacheOptions } from 'appolo-cache'
const CacheOptions = require('appolo-cache').CacheOptions
Type-only import for TypeScript users; requires using import type or importing the interface directly.
default import
import { Cache } from 'appolo-cache'
import Cache from 'appolo-cache'
There is no default export; only named export Cache is available.

Demonstrates basic CRUD operations: creating a Cache with maxSize and maxAge, setting and getting values, checking size, and resetting.

import { Cache } from 'appolo-cache'; // Create a cache with max 5 items and default TTL of 1 second const cache = new Cache<string, string>({ maxSize: 5, maxAge: 1000 }); // Add an item cache.set('greeting', 'Hello'); // Retrieve it console.log(cache.get('greeting')); // 'Hello' // Check size console.log(cache.size); // 1 // Reset the cache cache.reset(); console.log(cache.size); // 0
Debug
Known issues
gotchaCache constructor expects an options object; passing no arguments or undefined will use defaults (maxSize=1000, no maxAge).
fix
Always pass options object if you need to customize maxSize or maxAge: new Cache<K,V>({ maxSize: 100 })
affects: >=1.0.0
gotchaget() returns null for missing or expired keys, not undefined. This can cause issues when checking for existence.
fix
Use has() before get() if you need to distinguish between missing and null values, or check for null explicitly.
affects: >=1.0.0
gotchaset() with no maxAge argument uses the global maxAge from constructor options. If no global maxAge, the item never expires.
fix
Set maxAge in constructor or pass it explicitly in set() to control per-item expiration.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'Cache')
Attempting to import Cache incorrectly using CommonJS without destructuring: const Cache = require('appolo-cache');
fix
const { Cache } = require('appolo-cache');
Error: Cannot find module 'appolo-cache'
Package not installed or import path incorrect.
fix
Run 'npm install appolo-cache' and ensure no typos in import statement.
Upgrade
Version history
8.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
32 hits · last 30 days
node
28
Resources
appolo-cache — npm install appolo-cache · libregistry