evicting-cache 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,2 +1,39 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# Evicting Cache
|
|
2
|
+
JavaScript Cache using an LRU (Least Recently Used) algorithm
|
|
3
|
+
|
|
4
|
+
The cache is backed by a LinkedMap, which is a Map that maintains insertion order. When the cache is full, the least recently used item is evicted.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
// pnpm 🎉
|
|
10
|
+
pnpm add evicting-cache
|
|
11
|
+
|
|
12
|
+
// npm 🤷🏽♂️
|
|
13
|
+
npm install evicting-cache
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
```javascript
|
|
18
|
+
import EvictingCache from 'evicting-cache';
|
|
19
|
+
|
|
20
|
+
// Constructor accepts a number, which is the maximum number of items to store.
|
|
21
|
+
// default is 100
|
|
22
|
+
const cache = new EvictingCache(3);
|
|
23
|
+
|
|
24
|
+
// Obviously a contrived example, but this is what you get with AI...
|
|
25
|
+
cache.put('key1', 'value1');
|
|
26
|
+
cache.put('key2', 'value2');
|
|
27
|
+
cache.put('key3', 'value3');
|
|
28
|
+
cache.put('key4', 'value4');
|
|
29
|
+
|
|
30
|
+
console.log(cache.get('key1')); // undefined
|
|
31
|
+
console.log(cache.get('key2')); // value2
|
|
32
|
+
console.log(cache.get('key3')); // value3
|
|
33
|
+
console.log(cache.get('key4')); // value4
|
|
34
|
+
|
|
35
|
+
cache.put('key5', 'value5');
|
|
36
|
+
|
|
37
|
+
console.log(cache.get('key2')); // undefined
|
|
38
|
+
|
|
39
|
+
```
|