Registry / storage / local-cache

local-cache

JSON →
library0.1.0jsnpmunverified

A lightweight Node.js local JSON cache for reading and writing JSON objects to disk. Version 0.1.0 is the current release with no defined release cadence. It offers simple synchronous file operations for small-scale caching needs, but lacks asynchronous support, TTL, or advanced features found in alternatives like node-cache or flat-cache. Best suited for quick prototyping or non-performance-critical scripts.

npm install local-cache
INSTALL
IMPORT
SIG · LOCAL-CACHE
L
local-cache
storagejavascriptv0.1.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
const Cache = require('local-cache');
import Cache from 'local-cache';
CommonJS only; no ESM support.
Cache
const Cache = require('local-cache');
const { Cache } = require('local-cache');
Exported as a constructor, not a named export.
Cache instance
const cache = new Cache();
const cache = Cache();
Must be instantiated with new.

Shows synchronous write and read of a JSON object to a local cache file.

const Cache = require('local-cache'); const cache = new Cache(); cache.write('stats', { users: 100 }); const data = cache.read('stats'); console.log(data); // { users: 100 }
Debug
Known issues
gotchaNo asynchronous methods: all I/O is synchronous, blocking event loop.
fix
Use for small scripts or wrap in async function with worker threads if needed.
affects: >=0.0.0
gotchaNo TTL or cache expiration; entries persist until manually deleted.
fix
Implement your own cleanup or use a library with TTL support.
affects: >=0.0.0
gotchaNo error handling on file I/O; throws exceptions on disk issues.
fix
Wrap calls in try-catch blocks.
affects: >=0.0.0
gotchaCache files are stored in current working directory with no configurable path.
fix
Use absolute paths or chdir before instantiation.
affects: >=0.0.0
Errors
Common errors & fixes
Error: ENOENT: no such file or directory, open '...'
File not found or path does not exist.
fix
Ensure the directory exists or create it before using cache.
TypeError: cache.write is not a function
Forgot to instantiate Cache with new keyword.
fix
Use `const cache = new Cache();`
SyntaxError: Unexpected token u in JSON at position 0
Reading an empty or invalid JSON file.
fix
Check file content or use try-catch to handle parse errors.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

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