1.1.5 • Published 4 months ago

use-lru-cache v1.1.5

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months ago

**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
1.1.5

4 months ago

1.1.4

4 months ago

1.1.3

5 months ago

1.1.2

5 months ago

1.1.1

5 months ago

1.1.0

5 months ago

1.0.10

5 months ago

1.0.9

5 months ago

1.0.8

5 months ago

1.0.7

5 months ago

1.0.6

5 months ago

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago