GithubHelp home page GithubHelp logo

kikobeats / hyperlru Goto Github PK

View Code? Open in Web Editor NEW
34.0 3.0 6.0 64 KB

Tiny & Fast LRU Implementation as possible.

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

License: MIT License

JavaScript 100.00%
lru lru-cache cache

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: High performance (See benchmark).
  • Simple: The whole project is ~60 lines of code.
  • Lightweight: The package weighs less than a megabyte, with zero dependencies.

There are a lot of LRU implementations, but most of them have a poor perfomance and they are hard to understand.

hyperlru is an Abstract LRU implementation using traditional and efficienty data structures:

  • Double Linked List: It maintains the least recent list of items.
  • Hash Table It keeps the data for easily access to cache content.

For use it, you need to provide one of the created providers:

Install

$ npm install hyperlru --save

Usage

const hyperlru = require('hyperlru')
const myProvider = require('my-hyperlru-provider')

const createLRU = hyperlru(myProvider)
const cache = createLRU({ max: 1000 })

Benchmark

name size gzip set get1 update get2 evict
lru-fast 2.34 kB 793 B 6855 27105 21550 25159 4003
tiny-lru 4 kB 1.64 kB 4159 10746 18909 15925 4042
lru_cache 2.19 kB 756 B 5320 14489 10785 15963 4242
simple-lru-cache 1.43 kB 565 B 3289 12134 8600 15266 3334
hyperlru-object 433 B 265 B 1152 8800 6205 8635 1039
hashlru 628 B 332 B 4438 5834 4703 5960 3474
hyperlru-map 329 B 232 B 850 4555 4030 4397 690
lru 6.07 kB 1.86 kB 2672 3302 3142 3898 1347
lru-cache 19.1 kB 6.23 kB 989 4702 3034 4536 773
secondary-cache 22.6 kB 6.54 kB 1427 2292 2740 4579 1164
quick-lru 1.23 kB 489 B 2441 2075 2525 2119 2525
modern-lru 2.27 kB 907 B 1019 2531 2021 2456 731
mkc 10.5 kB 3.61 kB 729 1230 715 1129 575

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.

.peek(key)

Query the value of the key without marking 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.

.values()

It retrieves all the values currently in the cache.

.clear()

Clear all the elements in the cache.

.remove(key)

Remove the value from the cache.

Returns: value of key if found; undefined otherwise.

License

MIT © Kiko Beats.

hyperlru's People

Contributors

dependabot-preview[bot] avatar greenkeeper[bot] avatar kikobeats avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

hyperlru's Issues

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.

Since we did not receive a CI status on the greenkeeper/initial branch, we assume that you still need to configure it.

If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you don’t want it to run on every branch, you can whitelist branches starting with greenkeeper/.

We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

Once you have installed CI on this repository, you’ll need to re-trigger Greenkeeper’s initial Pull Request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organiszation’s settings page, under Installed GitHub Apps.

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.