sieve

a simple yet efficient cache, original introduction

algo animation

Usage

for Node.js, install via npm: npm install @zf/sieve

import { SieveCache, LRUCache } from '@zf/sieve'

const cache = new SieveCache<string>(3 /* capacity */)
cache.set('key', 'value')
cache.get('key')

for Deno

import { SieveCache, LRUCache } from "https://deno.land/x/sieve/mod.ts"

Benchmark

benchmark reading 1 million normally distributed items through a cache with a capacity of 100 compared with the LRU package, it is more performant, while the cache hit/miss ratio is similar:

chart

it seems that the LRU package's implementation is not very efficient, so I wrote my own LRU, and it actually better than SIEVE, which is not surprising:

chart

Dev

deno test
deno run --allow-all build_npm.ts 1.0.0