Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
🔥 An extremely fast and efficient LRU cache for JavaScript (Browser compatible) — 6.7KB.
🔥 An extremely fast and efficient LRU Cache for JavaScript (Browser compatible) — 6.7KB.
# Node.js
npm i lru.min
# Bun
bun add lru.min
# Deno
deno add npm:lru.min
import { createLRU } from 'lru.min';
const { createLRU } = require('lru.min');
<script src="https://cdn.jsdelivr.net/npm/lru.min/browser/lru.min.js"></script>
Set maximum size when creating LRU.
import { createLRU } from 'lru.min';
const LRU = createLRU({ max: 150_000 });
Also, you can set a callback for every deletion/eviction:
const LRU = createLRU({
max: 150_000,
onEviction: (key, value) => {
// do something
},
});
Adds a key-value pair to the cache. Updates the value if the key already exists
LRU.set('key', 'value');
undefined
keys will simply be ignored.
Retrieves the value for a given key and moves the key to the most recent position.
LRU.get('key');
Retrieves the value for a given key without changing its position.
LRU.get('key');
LRU.has('key');
LRU.delete('key');
Evicts the specified number of the oldest items from the cache.
LRU.evict(1000);
Resizes the cache to a new maximum size, evicting items if necessary.
LRU.resize(50_000);
Clears and disposes (if used) all key-value pairs from the cache.
LRU.clear();
LRU.max;
LRU.size;
LRU.available;
Iterates over all keys in the cache, from least recent to most recent.
const keys = [...LRU.keys()];
Iterates over all values in the cache, from least recent to most recent.
const keys = [...LRU.values()];
Iterates over [key, value]
pairs in the cache, from least recent to most recent.
const entries = [...LRU.entries()];
Iterates over [key, value]
pairs in the cache, from least recent to most recent.
const entries = [...LRU.entries()];
Iterates over each key-value pair in the cache, from most recent to least recent.
LRU.forEach((key, value) => {
// do something
});
The benchmark is performed by comparing 1,000,000
runs through a maximum cache limit of 100,000
, getting 333,333
caches and delenting 200,000
keys 10 consecutive times, clearing the cache every run.
# Time:
lru.min: 240.45ms
lru-cache: 258.32ms
quick-lru: 279.89ms
# CPU:
lru.min: 275558.30µs
lru-cache: 306858.30µs
quick-lru: 401318.80µs
Please check the SECURITY.md.
See the Contributing Guide and please follow our Code of Conduct 🚀
lru.min is based and inspired on the architecture and code of both lru-cache and quick-lru, simplifying their core concepts for enhanced performance and compatibility.
For more comprehensive features such as TTL support, consider using and supporting them 🤝
lru.min is under the MIT License.
Copyright © 2024-present Weslley Araújo and lru.min contributors.
FAQs
🔥 An extremely fast and efficient LRU cache for JavaScript with high compatibility (including Browsers) — 6.8KB.
The npm package lru.min receives a total of 622,403 weekly downloads. As such, lru.min popularity was classified as popular.
We found that lru.min demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.