Giter VIP home page Giter VIP logo

fast-lru-cache's Introduction

Least recently used cache

The fast and simple LRU cache realization.

  • No other dependencies;
  • Flyweight (~4.4KB or ~2.4KB if you minify it);
  • TypeScript typings;
  • Short and simple API.

Installation:

npm install fast-lru-cache --save

API

LRUCache

LRUCache<K, T> is a generic class that has two type parameters:

  • K - is a type of cache keys. The acceptable values are string or number;
  • T - is a type of cache entries. The acceptable value is any of the types.

constructor

constructor(max: number, unusedTimeout?: number, checkoutInterval?: number);
  • max - sets the maximum count of the cache entries. It is an integer and should not be less than 2. Also, it should not be equal to Infinity because, in that case, it will be a Map object with redundant functionality.
  • unusedTimeout(optional) - sets the maximum time in milliseconds, after which cache entries rates as unused. It should be more than 0 and not equal to Infinity. If this argument passed, the cache validity method will be called with the defined interval and cleanse unused cache entries.
  • checkoutInterval(optional) - sets the checkout interval in milliseconds of the validity of cache entries. It should be more than 0 and not equal to Infinity. The default value is equal to unusedTimeout.

get

get(key: K): T | null;

Gets a cache entry by the specified key. The method returns the null if the key is absent in a Cache object.

set

set(key: K, entry: T): void;

Adds a cache entry with a specified key. The method throws the error if a specified key already exists in a Cache object.

delete

delete(key: K): boolean;

Deletes a cache entry by the specified key and returns true if the specified key exists. Or false if the entry does not exist.

clear

clear(): void;

Clears a Cache object.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.