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

x/velo/src/cache/capabilities/timer_wheel.ts>TimerWheel

A high-performance caching library for Deno. Supports LRU, LFU, ARC, and TinyLFU.
Latest
class TimerWheel
import { TimerWheel } from "https://deno.land/x/velo@1.0.0/src/cache/capabilities/timer_wheel.ts";

Implementation of a timer wheel [1] to manage expiration of cache entries. Eviction events are stored in a hierarchical circular structure of buckets. Each bucket represents a rough time span (seconds, minutes, etc.). Based on Caffeine's implementation [2].

Constructors

new
TimerWheel(onExpire: OnExpire<K, V>)

Properties

private
base: number
private
onExpire: OnExpire<K, V>
private
time: number
private
wheel: TimerNode<K, V>[][]

Methods

private
applyBase(time: number)
private
expire(
index: number,
previousTicks: number,
delta: number,
)
private
findBucket(time: number)
advance(currentTimeMs?: number)
createAndSchedule(
key: K,
value: V,
time: number,
)
createNode(
key: K,
value: V,
time: number,
)

Creates a node and schedules it.

Removes a timer event from the wheel if present.

Schedules a TimerNode to be evicted, adding it to the correct bucket.

scheduleWithTime(node: TimerNode<K, V>, time: number)

Reschedules given node with time