@@ -23,21 +23,20 @@ const tempCache = lru(50, 5000);
2323tempCache .set (' session' , ' abc123' ); // Automatically expires after 5 seconds
2424```
2525
26- ## 🏆 Why Choose Tiny LRU?
26+ ## 📑 Table of Contents
2727
28- ### Benchmark Comparison
29-
30- | Library | SET ops/sec | GET ops/sec | UPDATE ops/sec | DELETE ops/sec | Bundle Size | Memory/Item |
31- | --------- | ------------- | ------------- | --------------- | --------------- | ------------- | ------------- |
32- | ** tiny-lru ** | 43,022 | 113,531 | ** 348,829 ** 🥇 | 335,038 | 2.2 KiB | 185 bytes |
33- | lru-cache | 27,819 | 96,739 | 133,706 | 149,700 | ~ 14.6 KiB | ** 114 bytes ** 🥇 |
34- | quick-lru | 52,200 | 118,758 | 321,377 | ** 391,763 ** 🥇 | ~ 1.8 KiB | 176 bytes |
35- | mnemonist | 29,933 | ** 192,073 ** 🥇 | 210,628 | N/A† | ~ 43.9 KiB | 99 bytes |
28+ - [ ✨ Features & Benefits ] ( #-features--benefits )
29+ - [ 📊 Performance Deep Dive ] ( #-performance-deep-dive )
30+ - [ 🚀 Getting Started ] ( #-getting-started )
31+ - [ 💡 Real-World Examples ] ( #-real-world-examples )
32+ - [ 🔗 Interoperability ] ( #-interoperability )
33+ - [ 🛠️ Development ] ( #️-development )
34+ - [ 📖 API Reference ] ( #-api-reference )
35+ - [ 📄 License ] ( #-license )
3636
37- † * mnemonist uses different method names for delete operations*
38- * Benchmarks run on Node.js v24.5.0, Apple Silicon (M4)*
37+ ## ✨ Features & Benefits
3938
40- ## ✨ ** What Makes Tiny LRU Useful **
39+ ### Why Choose Tiny LRU?
4140
4241- ** 🔄 Excellent Cache Updates** - 348K UPDATE ops/sec, outperforming alternatives by 2.6x
4342- ** 📦 Very Small Bundle** - Just 2.2 KiB minified for a full-featured LRU library
@@ -49,6 +48,18 @@ tempCache.set('session', 'abc123'); // Automatically expires after 5 seconds
4948- ** 🛡️ Production Ready** - 100% test coverage, battle-tested and reliable
5049- ** 🎛️ Rich Feature Set** - TTL, chaining, TypeScript support - all in 2.2 KiB
5150
51+ ### Benchmark Comparison
52+
53+ | Library | SET ops/sec | GET ops/sec | UPDATE ops/sec | DELETE ops/sec | Bundle Size | Memory/Item |
54+ | ---------| -------------| -------------| ---------------| ---------------| -------------| -------------|
55+ | ** tiny-lru** | 43,022 | 113,531 | ** 348,829** 🥇 | 335,038 | 2.2 KiB | 185 bytes |
56+ | lru-cache | 27,819 | 96,739 | 133,706 | 149,700 | ~ 14.6 KiB | ** 114 bytes** 🥇 |
57+ | quick-lru | 52,200 | 118,758 | 321,377 | ** 391,763** 🥇 | ~ 1.8 KiB | 176 bytes |
58+ | mnemonist | 29,933 | ** 192,073** 🥇 | 210,628 | N/A† | ~ 43.9 KiB | 99 bytes |
59+
60+ † * mnemonist uses different method names for delete operations*
61+ * Benchmarks run on Node.js v24.5.0, Apple Silicon (M4)*
62+
5263## 📊 Performance Deep Dive
5364
5465### Real-World Benchmarks
@@ -152,6 +163,61 @@ class MyCache extends LRU<User> {
152163}
153164```
154165
166+ ### Configuration Options
167+
168+ #### Factory Function
169+ ``` javascript
170+ import {lru } from " tiny-lru" ;
171+
172+ const cache = lru (max, ttl = 0 , resetTtl = false );
173+ ```
174+
175+ ** Parameters:**
176+ - ` max ` ` {Number} ` - Maximum number of items (0 = unlimited, default: 1000)
177+ - ` ttl ` ` {Number} ` - Time-to-live in milliseconds (0 = no expiration, default: 0)
178+ - ` resetTtl ` ` {Boolean} ` - Reset TTL on each ` get() ` operation (default: false)
179+
180+ #### Class Constructor
181+ ``` javascript
182+ import {LRU } from " tiny-lru" ;
183+
184+ const cache = new LRU (1000 , 60000 , true ); // 1000 items, 1 min TTL, reset on access
185+ ```
186+
187+ #### Best Practices
188+ ``` javascript
189+ // 1. Size your cache appropriately
190+ const cache = lru (1000 ); // Not too small, not too large
191+
192+ // 2. Use meaningful keys
193+ cache .set (` user:${ userId} :profile` , userProfile);
194+ cache .set (` product:${ productId} :details` , productDetails);
195+
196+ // 3. Handle cache misses gracefully
197+ function getData (key ) {
198+ const cached = cache .get (key);
199+ if (cached !== undefined ) {
200+ return cached;
201+ }
202+
203+ // Fallback to slower data source
204+ const data = expensiveOperation (key);
205+ cache .set (key, data);
206+ return data;
207+ }
208+
209+ // 4. Clean up when needed
210+ process .on (' exit' , () => {
211+ cache .clear (); // Help garbage collection
212+ });
213+ ```
214+
215+ #### Optimization Tips
216+ - ** Cache Size** : Keep cache size reasonable (1000-10000 items for most use cases)
217+ - ** TTL Usage** : Only use TTL when necessary; it adds overhead
218+ - ** Key Types** : String keys perform better than object keys
219+ - ** Memory** : Call ` clear() ` when done to help garbage collection
220+
155221## 💡 Real-World Examples
156222
157223### API Response Caching
@@ -246,66 +312,7 @@ class SessionManager {
246312}
247313```
248314
249- ## 🔧 Configuration & Best Practices
250-
251- ### Factory Function
252-
253- ``` javascript
254- import {lru } from " tiny-lru" ;
255-
256- const cache = lru (max, ttl = 0 , resetTtl = false );
257- ```
258-
259- ** Parameters:**
260- - ` max ` ` {Number} ` - Maximum number of items (0 = unlimited, default: 1000)
261- - ` ttl ` ` {Number} ` - Time-to-live in milliseconds (0 = no expiration, default: 0)
262- - ` resetTtl ` ` {Boolean} ` - Reset TTL on each ` set() ` operation (default: false)
263-
264- ### Class Constructor
265-
266- ``` javascript
267- import {LRU } from " tiny-lru" ;
268315
269- const cache = new LRU (1000 , 60000 , true ); // 1000 items, 1 min TTL, reset on access
270- ```
271-
272- ### Best Practices
273-
274- ``` javascript
275- import {lru } from " tiny-lru" ;
276-
277- // 1. Size your cache appropriately
278- const cache = lru (1000 ); // Not too small, not too large
279-
280- // 2. Use meaningful keys
281- cache .set (` user:${ userId} :profile` , userProfile);
282- cache .set (` product:${ productId} :details` , productDetails);
283-
284- // 3. Handle cache misses gracefully
285- function getData (key ) {
286- const cached = cache .get (key);
287- if (cached !== undefined ) {
288- return cached;
289- }
290-
291- // Fallback to slower data source
292- const data = expensiveOperation (key);
293- cache .set (key, data);
294- return data;
295- }
296-
297- // 4. Clean up when needed
298- process .on (' exit' , () => {
299- cache .clear (); // Help garbage collection
300- });
301- ```
302-
303- ### Optimization Tips
304-
305- - ** Cache Size** : Keep cache size reasonable (1000-10000 items for most use cases)
306- - ** TTL Usage** : Only use TTL when necessary; it adds overhead
307- - ** Key Types** : String keys perform better than object keys
308- - ** Memory** : Call ` clear() ` when done to help garbage collection
309316
310317## 🔗 Interoperability
311318
@@ -320,7 +327,9 @@ const memoized = _.memoize(myFunc);
320327memoized .cache .max = 10 ;
321328```
322329
323- ## 🧪 Testing
330+ ## 🛠️ Development
331+
332+ ### Testing
324333
325334Tiny LRU maintains 100% test coverage with comprehensive unit and integration tests.
326335
@@ -338,7 +347,7 @@ npm run lint
338347npm run build
339348```
340349
341- ### Test Coverage
350+ ** Test Coverage: ** 100% coverage across all modules
342351
343352``` console
344353----------|---------|----------|---------|---------|-------------------
@@ -349,7 +358,7 @@ All files | 100 | 100 | 100 | 100 |
349358----------|---------|----------|---------|---------|-------------------
350359```
351360
352- ## 🤝 Contributing
361+ ### Contributing
353362
354363We welcome contributions! Here's how you can help:
355364
0 commit comments