2.0.0 • Published 6 months ago
simple-kv-cache v2.0.0
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
npm i simple-kv-cache
Usage
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">()
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
2.0.0
6 months ago
1.2.0
1 year ago
1.1.1
1 year ago
1.1.0
1 year ago
1.0.1
1 year ago
1.0.0
1 year ago
1.2.4
1 year ago
1.2.3
1 year ago
1.2.2
1 year ago
1.2.1
1 year ago
0.1.0
1 year ago
0.1.1
1 year ago
0.0.8
1 year ago
0.0.5
1 year ago
0.0.4
1 year ago
0.0.7
1 year ago
0.0.6
1 year ago
0.0.3
1 year ago
0.0.2
1 year ago
0.0.1
1 year ago