Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
The ylru package is a simple and efficient LRU (Least Recently Used) cache implementation in JavaScript. It is designed to help manage a cache of items with a fixed size, automatically removing the least recently used items when the cache exceeds its capacity. This is particularly useful in applications where memory management and data retrieval efficiency are critical.
Create and manage an LRU cache
This feature allows the user to create a cache with a specified limit and perform basic operations such as setting, getting, checking, and deleting items, as well as retrieving the size of the cache.
const YLRU = require('ylru');
let cache = new YLRU(100); // Create a cache that can hold 100 items
// Set items in the cache
cache.set('key1', 'value1');
cache.set('key2', 'value2');
// Get an item from the cache
let value = cache.get('key1'); // returns 'value1'
// Check if a key exists in the cache
let exists = cache.has('key1'); // returns true
// Remove an item from the cache
cache.delete('key2');
// Get the number of items in the cache
let size = cache.size(); // returns 1
lru-cache is another popular LRU cache implementation. It offers additional features such as item expiration based on time, which ylru does not support. This makes lru-cache suitable for scenarios where cache items should expire after a certain duration.
node-cache is a more general caching library that supports both LRU mechanism and other types of cache strategies. Unlike ylru, which is specifically focused on LRU, node-cache provides a more flexible solution for various caching needs.
hashlru inspired
hashlru is the Simpler, faster LRU cache algorithm. Please checkout algorithm and complexity on hashlru.
ylru extends some features base on hashlru:
null
, undefined
, ''
, 0
const LRU = require('ylru');
const lru = new LRU(100);
lru.set(key, value);
lru.get(key);
// value2 will be expired after 5000ms
lru.set(key2, value2, { maxAge: 5000 });
lru.get(key2);
initialize a lru object.
Returns the value in the cache.
{Number} options.maxAge
: value will become undefined
after maxAge
pass.
If maxAge
not set, value will be never expired.Set the value for key.
FAQs
Extends LRU base on hashlru
The npm package ylru receives a total of 2,168,605 weekly downloads. As such, ylru popularity was classified as popular.
We found that ylru demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.