Registry / storage / ls-cache

ls-cache

JSON →
library0.2.3jsnpmunverified

ls-cache (version 0.2.3) is a browser library that emulates memcache functions using HTML5 localStorage. It stores key-value pairs with optional expiration times in minutes, automatically evicts expiring entries when the ~5MB limit is approached, and degrades gracefully if localStorage is unavailable. Supports hierarchical buckets for independent caching scopes. Current version is 0.2.3; no recent releases. Differentiates from lscache by adding bucket hierarchies and a non-global namespace.

npm install ls-cache
INSTALL
IMPORT
SIG · LS-CACHE
L
ls-cache
storagejavascriptv0.2.3
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.

default
import lscache from 'ls-cache'
const lscache = require('ls-cache')
ESM default import. The package does not export a named module; CommonJS require may not work in all bundlers.
lscache
import lscache from 'ls-cache'
import { lscache } from 'ls-cache'
Named import does not exist. The package exports a default object.
createBucket
import lscache from 'ls-cache'; const bucket = lscache.createBucket('name')
import { createBucket } from 'ls-cache'
createBucket is a method on the default export, not a separate export.

Demonstrates basic set/get with expiration, object storage, removal, flush, and hierarchical buckets.

import lscache from 'ls-cache'; // Set a value with 2 minute expiration lscache.set('greeting', 'Hello World!', 2); // Get the value const greeting = lscache.get('greeting'); console.log(greeting); // 'Hello World!' // Store objects lscache.set('data', { name: 'Pamela', age: 26 }, 2); const data = lscache.get('data'); console.log(data.name); // 'Pamela' // Remove a specific key lscache.remove('greeting'); // Clear all cached items in the current bucket lscache.flush(); // Create a sub-bucket const bucket = lscache.createBucket('sub'); bucket.set('key', 'value', 5); console.log(bucket.get('key')); // 'value'
Debug
Known issues
deprecatedThis package is not actively maintained; last release was over a decade ago.
fix
Consider using a maintained alternative like lscache-ts or implementing your own wrapper.
affects: >=0.0.0
gotchals-cache uses localStorage which is synchronous and blocks the main thread on large data sets.
fix
Avoid storing large objects; keep data small to prevent UI jank.
affects: >=0.0.0
gotchaExpiration times are in minutes, not milliseconds.
fix
Always pass minutes. For example, 1 hour = 60.
affects: >=0.0.0
gotchaIf localStorage is full, ls-cache evicts only entries that are closest to expiring. Persistent entries with no expiry are never evicted and may cause storage errors.
fix
Set expiration on all entries to allow automatic eviction. Or handle QuotaExceededError manually.
affects: >=0.0.0
gotchaBuckets are flat; createBucket returns a new object with its own set of methods, but all data is stored under a common namespace. Flush on a parent bucket does NOT affect sub-buckets (only flushRecursive does).
fix
Use flushRecursive to clear a bucket and all its children.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'ls-cache'
Package not installed or import path incorrect.
fix
Run npm install ls-cache, then import lscache from 'ls-cache'.
TypeError: lscache.set is not a function
Named import used instead of default import.
fix
Use import lscache from 'ls-cache' instead of import { lscache } from 'ls-cache'.
QuotaExceededError: Failed to execute 'setItem' on 'Storage'
localStorage is full. ls-cache could not free enough space by evicting expiring entries.
fix
Reduce stored data size, ensure most entries have expiration times, or call lscache.flush() manually to clear space.
ReferenceError: lscache is not defined
ls-cache is not loaded or imported.
fix
Add <script src='ls-cache.js'></script> or import lscache properly.
Upgrade
Version history
0.2.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
ls-cache — npm install ls-cache · libregistry