Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@types/lru-cache

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/lru-cache

TypeScript definitions for lru-cache

  • 4.1.0
  • npm
  • Socket score

Version published
Weekly downloads
1.8M
decreased by-6.33%
Maintainers
1
Weekly downloads
 
Created

What is @types/lru-cache?

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.

What are @types/lru-cache's main functionalities?

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');

Other packages similar to @types/lru-cache

FAQs

Package last updated on 24 Aug 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc