Registry / storage / micro-cache

micro-cache

JSON →
library3.0.3jsnpmunverified

Micro-cache (v3.0.3) is a minimal synchronous file system cache for Node.js. It writes/reads files to a local directory synchronously, with no runtime memory caching. Designed for simplicity, it uses the file system exclusively, not memory. The package is ES module (no CommonJS), requires Node >=12, and has no dependencies. It is a niche tool for scenarios requiring a persistent, synchronous, file-based cache with minimal overhead.

npm install micro-cache
INSTALL
IMPORT
SIG · MICRO-CACHE
M
micro-cache
storagejavascriptv3.0.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.

MicroCache
import MicroCache from 'micro-cache'
const MicroCache = require('micro-cache')
Package is ESM-only; CommonJS require() will fail. TypeScript users may need to set 'esModuleInterop'.
MicroCache (TypeScript type)
import type MicroCache from 'micro-cache'
For type-only imports in TypeScript.
Dynamic import
const MicroCache = await import('micro-cache')
const MicroCache = require('micro-cache').default
Dynamic import with then() or await works; do not mix require with default.

Shows basic synchronous file cache operations: write, read, delete, and conditional write. The cache persists to disk.

import MicroCache from 'micro-cache'; const cache = new MicroCache('./cache'); // Write and overwrite cache.write('testFile', 'Hello, world!'); // Write only if not exists cache.write('testFile2', 'Only if new', true); // Read const data = cache.read('testFile'); console.log(data); // 'Hello, world!' // Delete cache.remove('testFile'); // Check existence (by read, no separate has method) const exists = cache.read('nonexistentFile') !== undefined; console.log(exists); // false
Debug
Known issues
breakingESM-only module; CommonJS require() will throw an error.
fix
Use import (ESM) or dynamic import; or downgrade to version 2.x if CommonJS is required.
affects: >=3.0.0
deprecatedThe 'has' method is not available; check existence by reading the file.
fix
Use cache.read(key) !== undefined to test existence.
affects: >=3.0.0
gotchaOperations are synchronous and will block the event loop.
fix
Only use in scripts or for small caches; avoid in high-concurrency production servers.
affects: >=1.0.0
gotchaFile names are used as-is; invalid file system characters or paths will cause errors.
fix
Sanitize keys (e.g., replace / with -) or use a hashing function.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Package is ESM-only but the project is using CommonJS (e.g., 'type': 'commonjs' in package.json or node --require).
fix
Add 'type': 'module' to package.json or use .mjs extension, or downgrade to micro-cache@2.x.
TypeError: cache.write is not a function
Using CommonJS require() which does not return the default export correctly.
fix
Use import MicroCache from 'micro-cache' or const { default: MicroCache } = require('micro-cache').
Error: ENOENT: no such file or directory, open './cache/nonexistent'
Cache directory does not exist or the path is incorrect.
fix
Ensure the cache directory exists before instantiation (e.g., fs.mkdirSync('./cache', { recursive: true })).
Upgrade
Version history
3.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
micro-cache — npm install micro-cache · libregistry