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.
@types/lru-cache
Advanced tools
The @types/lru-cache package provides TypeScript type definitions for the lru-cache package, enabling developers to use LRU (Least Recently Used) caching mechanism in TypeScript projects with type checking. This package does not implement LRU cache logic itself but offers type support for the lru-cache package, ensuring that developers can work with clear and predictable type definitions for better code quality and maintainability.
Creating an LRU Cache
This code demonstrates how to create an LRU cache instance with a maximum of 100 items and items expiring after an hour. The cache keys are of type string, and the values can be of any type.
import LRU from 'lru-cache';
const options = {
max: 100,
maxAge: 1000 * 60 * 60
};
const cache = new LRU<string, any>(options);
Setting and Getting Cache Items
This code snippet shows how to set a value in the cache with a specific key and then retrieve that value using the key. The 'set' method adds or updates an entry, and the 'get' method retrieves an entry if it exists and is not expired.
cache.set('key', 'value');
const value = cache.get('key');
Checking if a Key Exists
This example demonstrates checking if a specific key exists in the cache without updating the recent-ness or expiration of the item.
const hasKey = cache.has('key');
Deleting a Cache Item
This code sample illustrates how to delete a specific item from the cache using its key.
cache.del('key');
node-cache is a simple caching module for Node.js that offers in-memory storage. Unlike lru-cache, it does not inherently support LRU eviction policy but provides a straightforward API for key-value storage with TTL support.
memory-cache is another simple in-memory cache for Node.js applications. It provides basic functionality similar to node-cache and does not specifically implement LRU logic, focusing instead on simplicity and ease of use.
quick-lru is a fast and efficient LRU cache implementation. It offers a similar LRU caching mechanism to lru-cache but focuses on performance and simplicity, with a minimalistic API and optimized operations for high-speed caching scenarios.
npm install --save @types/lru-cache
This package contains type definitions for lru-cache (https://github.com/isaacs/node-lru-cache).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/lru-cache
Additional Details
These definitions were written by Bart van der Schoor https://github.com/Bartvds, BendingBender https://github.com/BendingBender.
FAQs
Stub TypeScript definitions entry for lru-cache, which provides its own types definitions
The npm package @types/lru-cache receives a total of 1,222,048 weekly downloads. As such, @types/lru-cache popularity was classified as popular.
We found that @types/lru-cache demonstrated a not healthy version release cadence and project activity because the last version was released 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.