A mini LRU implementation library. If you have lightweight LRU needs, we recommend you give it a try.
English | 简体中文
- Supports setting the number of cache entries
- Supports setting the expiration time for each cache entry
step1: import the file and initialize
import LRUCacheLite from "lru-cache-lite"
const cacheIns = new LRUCacheLite(10); // Specify the cache size as 10
step2: Set or read the cache
// Set cache with set(key, value, expireTime(seconds))
cacheIns.set('demo', 'demo-value', 10)
// Read cache
cacheIns.get('demo') // 'demo-value'
const objKey = {};
const objValue = {};
cacheIns.set(objKey, objValue)
console.log(objValue === cacheIns.get(objKey)) // true
- Front-end API interface caching
- Front-end business content caching