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

use-lru-cache

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-lru-cache

Optimize your React applications by effortlessly implementing Least Recently Used (LRU) caching for time-consuming API responses with the React LRUCache Hook. This lightweight and easy-to-use hook seamlessly integrates into your components, allowing you t

  • 1.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
decreased by-85.71%
Maintainers
1
Weekly downloads
 
Created
Source

useLRUCache🪝

A React hook for managing an LRUCache (Least Recently Used Cache) in your React components.

Installation

npm install use-lru-cache

Usage

import React from "react";
import { useLRUCache } from "use-lru-cache";

type T = number;

const App: React.FC = () => {
  // Initialize an LRUCache with a capacity of 10 for numbers
  // It will hold a value of type number against keys
  const { get, put, getCachedData, clearCache } = useLRUCache<T>(10);

  const cachedValue = get("someKey"); // returns corresponding value if key is present else null.
  put("someKey", 42); // set key as "someKey" and corresponding value will be 42
  const cachedKeys = getCachedData(); // will return an array of all present keys

  return (
    <div>
      <p>Cached Value: {cachedValue}</p>
      {/* Render other components or UI elements */}
    </div>
  );
};

export default MyComponent;

Note: Replace someKey and 42 with your actual key and data. Adjust the generic type parameter based on the type of data you want to store in the cache corresponding to your key. A key can be a number or string.

Example: use-lru-cache.vercel.app
Checkout use-lru-cache on npm
Contributors

Keywords

FAQs

Package last updated on 30 Dec 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