Skip to main content
Module

x/velo/src/caches/base.ts>BaseCache

Performant Cache implementations for Deno. Supports LRU, LFU, ARC and other caching policies.
Go to Latest
class BaseCache
extends EventEmitter
Abstract
import { BaseCache } from "https://deno.land/x/velo@0.1.5/src/caches/base.ts";

Constructors

new
BaseCache(options: Options)

Properties

protected
_stats: CacheStatistics
readonly
capacity: number

Maximum number of entries in the cache

readonly
optional
clearEvent: boolean

True if the cache emits an event when the cache gets cleared

readonly
optional
expiredEvent: boolean

True if the cache emits an event when a key expires

readonly
optional
removeEvent: boolean

True if the cache emits an event when a key gets removed

readonly
optional
setEvent: boolean

True if the cache emits an event when a key gets added

readonly
stats: CacheStatistics

Cache statistics containing amount of keys, total hits and total misses

readonly
optional
stdTTL: number

Maximum time to live in ms

Methods

protected
applyClearEvent()
protected
applyExpiredEvent(key: Key, value: V)
protected
applyRemoveEvent(key: Key, value: V)
protected
applySetEvent(key: Key, value: V)
protected
applyTTL(key: Key, ttl?: number)
abstract
clear(): void
abstract
forEach(callback: (item: { key: Key; value: V; }, index: number) => void): void
abstract
get(key: Key): V | undefined
abstract
has(key: Key): boolean
abstract
peek(key: Key): V | undefined
abstract
remove(key: Key): void
abstract
set(
key: Key,
value: V,
ttl?: number,
): void
setTTL(key: Key, ttl: number)

Adds a TTL to given key. Does however not override any existing TTLs.

take(key: Key): V | undefined

Returns the value for a given key while removing this key from the cache. Equal to calling get and remove.

interface BaseCache
import { type BaseCache } from "https://deno.land/x/velo@0.1.5/src/caches/base.ts";

Methods

on(event: "remove", listener: (key: Key, value: V) => void): this
on(event: "set", listener: (key: Key, value: V) => void): this
on(event: "clear", listener: () => void): this
on(event: "expired", listener: (key: Key, value: V) => void): this
on(event: string, listener: Function): this