sieve
a simple yet efficient cache, original introduction
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 showing SIEVE is more performant, while the cache hit/miss ratio is about the same:
It turned out that the LRU package's implementation is not very efficient, so I wrote my own LRU, and it actually better than SIEVE:
Anyway, the cache hit/miss ratio is of much greater importance, and it is determined by the data distribution.
Dev
deno test
deno run --allow-all build_npm.ts 1.0.0