lru-cache
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
yallist | 4.0.0 | 4.39 kB | ISC | prod |
The "lru-cache" is a node package that provides a JavaScript implementation of a Least Recently Used (LRU) cache. An LRU cache deletes the least recently used items to make space for recently used items. You can specify a maximum number of the most recently used items, beyond which the least recently used items get deleted. Although primarily not a TTL cache, you can also set a Time to Live (TTL) on the cache or on a single "set" operation. As of version 7, "lru-cache" is noted as being one of the most performant JavaScript LRU cache implementations available. The library supports a wide variety of use cases, though utilizing some features may affect performance by increasing the workload of the cache.
To use the "lru-cache" package in your JavaScript project, you first need to install it via npm by running npm install lru-cache --save
in your terminal. Once installed, the "lru-cache" can be utilized by importing it into your JavaScript file. Here's an example of a minimal usage scenario:
const { LRUCache } = require('lru-cache');
const options = {
max: 500,
ttl: 1000 * 60 * 5, // 5 minutes in milliseconds
};
const cache = new LRUCache(options);
cache.set('key', 'value'); // set a value
console.log(cache.get('key')); // retrieve the value
cache.delete('key'); // delete value
cache.clear(); // empty the cache
The "lru-cache" module allows the use of non-string keys and setting of various options. For example, max storage limit, disposal mechanism for evicted objects, TTL, and setting asynchronous methods for cache.fetch()
function.
The documentation for the "lru-cache" is available on the GitHub repository of the package, under this URL: git://github.com/isaacs/node-lru-cache.git. The readme file in the main directory of the repository provides all the necessary information on how to install and use the package, as well as detailed descriptions of its features and options.