Socket
Socket
Sign inDemoInstall

tiny-lru

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiny-lru

Tiny LRU cache for Client or Server


Version published
Weekly downloads
1.2M
decreased by-6.4%
Maintainers
1
Weekly downloads
 
Created

What is tiny-lru?

The tiny-lru npm package is a lightweight, in-memory Least Recently Used (LRU) cache. It is designed to be simple and efficient, making it suitable for use in environments where memory usage and performance are critical.

What are tiny-lru's main functionalities?

Creating an LRU Cache

This feature allows you to create an LRU cache with a specified maximum size. The cache will automatically evict the least recently used items when the size limit is reached.

const LRU = require('tiny-lru');
const cache = LRU(100); // Create a cache with a max size of 100 items

Setting and Getting Cache Items

You can store items in the cache using the `set` method and retrieve them using the `get` method. If the item is not found, `get` will return `undefined`.

cache.set('key', 'value');
const value = cache.get('key'); // 'value'

Deleting Cache Items

This feature allows you to delete specific items from the cache using the `delete` method.

cache.set('key', 'value');
cache.delete('key');
const value = cache.get('key'); // undefined

Clearing the Cache

You can clear all items from the cache using the `clear` method, which removes all entries.

cache.set('key1', 'value1');
cache.set('key2', 'value2');
cache.clear();
const value1 = cache.get('key1'); // undefined
const value2 = cache.get('key2'); // undefined

Cache Size and Item Count

This feature allows you to check the current number of items in the cache using the `size` property.

cache.set('key1', 'value1');
cache.set('key2', 'value2');
const size = cache.size; // 2

Other packages similar to tiny-lru

Keywords

FAQs

Package last updated on 23 Mar 2023

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