GithubHelp home page GithubHelp logo

josebaseba / hyperlru Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kikobeats/hyperlru

0.0 2.0 0.0 29 KB

Tiny & Fast LRU Implementation as possible.

Home Page: https://kikobeats.github.io/hyperlru/

License: MIT License

JavaScript 100.00%

hyperlru's Introduction

hyperlru

Last version Build Status Coverage Status Dependency status Dev Dependencies Status NPM Status Donate

Tiny & Fast LRU Implementation as possible.

Features

  • Fast: Ultra-high performance (See benchmark).
  • Simple: The whole project is ~60 lines of code.
  • Lightweight: The package weighs less than a megabyte, with zero dependencies.

hyperlru claim to be fast and simple as possible. There are a lot of LRU implementations, but most of them have a poor perfomance and they are hard to understand.

It's Inspired by the hashlru algorithm.

Install

$ npm install hyperlru --save

Usage

const hyperlru = require('hyperlru')
const cache = hyperlru({max: 1000})

Benchmark

name size gzip set get1 update get2 evict
lru-cache 19.1 kB 6.23 kB 922 ops 3030 ops 2105 ops 4082 ops 917 ops
modern-lru 2.27 kB 907 B 813 ops 1299 ops 752 ops 1515 ops 629 ops
mkc 10.5 kB 3.61 kB 784 ops 766 ops 810 ops 1149 ops 697 ops
lru_cache 2.19 kB 756 B 6452 ops 18182 ops 14286 ops 9524 ops 3509 ops
hashlru 628 B 332 B 5263 ops 6897 ops 4545 ops 7407 ops 3922 ops
tiny-lru 4 kB 1.64 kB 3509 ops 11765 ops 15385 ops 11765 ops 2222 ops
quick-lru 1.23 kB 489 B 3279 ops 2198 ops 3226 ops 2105 ops 2778 ops
lru 6.07 kB 1.86 kB 2500 ops 3846 ops 3175 ops 3226 ops 976 ops
hyperlru 889 B 395 B 2299 ops 25000 ops 2410 ops 22222 ops 2439 ops
lru-fast 2.34 kB 793 B 1869 ops 6897 ops 4167 ops 16667 ops 3077 ops
simple-lru-cache 1.43 kB 565 B 1709 ops 13333 ops 5128 ops 22222 ops 3922 ops
secondary-cache 22.6 kB 6.54 kB 1695 ops 2632 ops 2667 ops 5556 ops 1408 ops

See more at bench-lru.

API

hyperlru([options])

options

max

Type: number
Default: 1000

Max of element to keep into the cache.

.set(key, value)

Set the value of the key and mark the key as most recently used.

It returns the value.

.get(key)

Query the value of the key and mark the key as most recently used.

It returns the value of key if found; undefined otherwise.

.keys()

It retrieves all the keys currently in the cache.

.clear()

Clear all the elements in the cache.

License

MIT © Kiko Beats.

hyperlru's People

Contributors

greenkeeper[bot] avatar kikobeats avatar

Watchers

 avatar  avatar

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.