adaptive-replacement-cache
v1.0.2
Published
A lightweight ARC cache implementation for Node.js and browsers.
Maintainers
Readme
Adaptive Replacement Cache
A lightweight ARC cache implementation for Node.js and browsers.
Features
- ✅ Adaptive Replacement Cache (ARC) algorithm
- ✅ Works in Node.js and browsers
- ✅ ES Modules & CommonJS support
- ✅ TypeScript type definitions included
Installation
# npm
npm install adaptive-replacement-cache
# pnpm
pnpm add adaptive-replacement-cache
# yarn
yarn add adaptive-replacement-cacheUsage
ES Modules
import { ARC, arc } from 'adaptive-replacement-cache';
// Direct class usage
const cache = new ARC(100);
cache.set('key', 'value');
console.log(cache.get('key'));
// Factory function
const cache2 = arc(100);CommonJS
const { ARC, arc } = require('adaptive-replacement-cache');
const cache = arc(100);
cache.set('key', 'value');
console.log(cache.get('key'));API
| Method | Description |
|--------|-------------|
| new ARC(size) | Create cache with max size |
| get(key) | Retrieve value by key |
| set(key, value) | Store value by key |
| delete(key) | Remove key from cache |
| has(key) | Check if key exists |
| clear() | Remove all entries |
| keys() | Iterator over keys |
| values() | Iterator over values |
| entries() | Iterator over [key, value] |
| forEach(callback) | Iterate with callback |
| toJSON() | Serialize to JSON |
| size | Current entry count (readonly) |
| maxSize | Maximum size (readonly) |
| arc(size) | Factory function |
See docs/API.md for full API documentation.
Development
# Install dependencies
npm install
# Run linting
npm run lint
# Fix formatting
npm run fix
# Run tests
npm test
# Build
npm run build
# Generate changelog
npm run changelogContributing
Contributions are welcome! Please read our contributing guidelines before submitting a PR.
License
BSD-3-Clause
Acknowledgments
- Inspired by the Adaptive Replacement Cache algorithm
