Socket
Socket
Sign inDemoInstall

@types/lru-cache

Package Overview
Dependencies
1
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/lru-cache

Stub TypeScript definitions entry for lru-cache, which provides its own types definitions


Version published
Maintainers
1
Weekly downloads
1,149,719
decreased by-9.47%

Weekly downloads

Package description

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

Readme

Source

This is a stub types definition for @types/lru-cache (https://github.com/isaacs/node-lru-cache#readme).

lru-cache provides its own type definitions, so you don't need @types/lru-cache installed!

FAQs

Last updated on 13 May 2022

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc