All Projects → Kikobeats → hyperlru

Kikobeats / hyperlru

Licence: MIT license
Tiny & Fast LRU Implementation as possible.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to hyperlru

gocache
High performance and lightweight in-memory cache library with LRU and FIFO support as well as memory-usage-based-eviction
Stars: ✭ 15 (-55.88%)
Mutual labels:  lru, lru-cache
memo-async-lru
Memoize Node.js style callback-last functions, using an in-memory LRU store
Stars: ✭ 17 (-50%)
Mutual labels:  lru, lru-cache
LruClockCache
A low-latency LRU approximation cache in C++ using CLOCK second-chance algorithm. Multi level cache too. Up to 2.5 billion lookups per second.
Stars: ✭ 35 (+2.94%)
Mutual labels:  lru, lru-cache
go-cache-benchmark
Cache benchmark for Golang
Stars: ✭ 47 (+38.24%)
Mutual labels:  lru, lru-cache
Olric
Distributed cache and in-memory key/value data store. It can be used both as an embedded Go library and as a language-independent service.
Stars: ✭ 2,067 (+5979.41%)
Mutual labels:  lru, lru-cache
disk-lru-cache
💾 Disk LRU cache with persisted journal
Stars: ✭ 21 (-38.24%)
Mutual labels:  lru, lru-cache
golib
Open version of common golang libraries useful to many projects.
Stars: ✭ 47 (+38.24%)
Mutual labels:  lru, lru-cache
cache
LRU-based cache package for Go.
Stars: ✭ 25 (-26.47%)
Mutual labels:  lru, lru-cache
lru
LRU cache using go generics
Stars: ✭ 108 (+217.65%)
Mutual labels:  lru, lru-cache
mcache
An in-memory cache library for golang. support: lru,lfu,hash-lru,hash-lfu,arc. 一个高性能本地内存缓存,带有各种内存淘汰算法
Stars: ✭ 311 (+814.71%)
Mutual labels:  lru
methodtools
Expand functools features(lru_cache) to class - methods, classmethods, staticmethods and even for (unofficial) hybrid methods.
Stars: ✭ 57 (+67.65%)
Mutual labels:  lru-cache
GoCache
A simplest Cache Server based on LRU implementation written in Go
Stars: ✭ 15 (-55.88%)
Mutual labels:  lru-cache
Algorithm-Implementation
This is our effort to collect the best implementations to tough algorithms. All codes are written in c++.
Stars: ✭ 16 (-52.94%)
Mutual labels:  lru-cache
Gcache
An in-memory cache library for golang. It supports multiple eviction policies: LRU, LFU, ARC
Stars: ✭ 1,787 (+5155.88%)
Mutual labels:  lru
gotcha
[Not Safe For Production] gotcha: inmemory-cache in Go (Golang) with customizable algorithm
Stars: ✭ 13 (-61.76%)
Mutual labels:  lru-cache
elara
Elara DB is an easy to use, lightweight key-value database that can also be used as a fast in-memory cache. Manipulate data structures in-memory, encrypt database files and export data. 🎯
Stars: ✭ 93 (+173.53%)
Mutual labels:  lru-cache

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].