https://github.com/tariqs26/lru-cache
LRU cache library
https://github.com/tariqs26/lru-cache
caching jest nodejs npm typescript
Last synced: 28 days ago
JSON representation
LRU cache library
- Host: GitHub
- URL: https://github.com/tariqs26/lru-cache
- Owner: tariqs26
- License: mit
- Created: 2024-01-19T00:52:58.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-26T06:08:21.000Z (4 months ago)
- Last Synced: 2025-01-26T07:18:34.079Z (4 months ago)
- Topics: caching, jest, nodejs, npm, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/simple-kv-cache
- Size: 232 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LRU Cache
LRU cache implemented with a hashmap and doubly linked list.
## Implementation
- **Hashmap**: Associates keys with doubly linked list nodes.
- **Doubly Linked List**: Manages entries by access recency.
- New entries are inserted at the head.
- When the cache is full, the tail (least recently used) entry is removed.
- Accessing an entry moves it to the head, updating its recency.## Installation
```bash
npm i simple-kv-cache
```## Usage
```ts
import { LRUCache } from "simple-kv-cache"const cache = new LRUCache({
maxCapacity: 5000, // default is 1000
})// store value
cache.set("users", [{ id: 1, name: "John Doe" }])// retrieve value
cache.get("users")// remove value
cache.remove("users")// remove all values
cache.clear()// support for generic types
const routeCache = new LRUCache<"/users" | "/posts">()
const cartCache = new LRUCache()
```## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.