Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/velo/mod.ts>Arc

A high-performance caching library for Deno. Supports LRU, LFU, ARC, and TinyLFU.
Latest
class Arc
implements Policy<K, V>
import { Arc } from "https://deno.land/x/velo@1.0.0/mod.ts";

Implementation of an Adaptive Replacement Cache (ARC) [1]. It adapitvely balances between recency and frequency. This is achieved by keeping track of evicted keys and their frequencies in ghost lists (b1 and b2). This increases the overall size of the cache, but allows for a better hit rate.

  • t1: for recent cache entries.
  • t2: for frequent entries, referenced at least twice.
  • b1: ghost entries recently evicted from the T1 cache, but are still tracked.
  • b2: similar ghost entries, but evicted from T2.

[1]https://www.usenix.org/legacy/events/fast03/tech/full_papers/megiddo/megiddo.pdf

Constructors

new
Arc(capacity: number)

Type Parameters

K extends Key
V

Properties

private
b1: ArcList<K, null>
private
b2: ArcList<K, null>
private
partition: number
private
t1: ArcList<K, V>
private
t2: ArcList<K, V>
readonly
capacity: number
readonly
keys
optional
onEvict: RemoveListener<K, V>
readonly
size
readonly
values

Methods

private
replace(in_t2: boolean)

Reset the cache

forEach(callback: (item: { key: K; value: V; }, index: number) => void)
get(key: K): V | undefined
has(key: K)
peek(key: K)
remove(key: K)

Removes the cache entry with given key

set(key: K, value: V)