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

x/velo/mod.ts>Velo

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

Builder class for Cache and LoadingCache. Allows to add optional functionality to a cache. The following options are available:

  • size-based eviction (capacity)
  • multiple cache strategies (policy, lru, lfu, arc, sc, tinyLfu)
  • automated loading of cache values (build(fn: LoaderFunction))
  • time-based expiration of entries (ttl)
  • listener for cache removals (removalListener)
  • eventEmitter for cache events (events)
  • collecting cache hit and miss statistics (stats)

All listed features are optional. By default the cache has no functionality.

Constructors

new
private
Velo()

Type Parameters

K extends Key
V

Properties

private
_options: CacheOptions<K, V>

Methods

private
requireExpr(expression: boolean, message?: string)

Enables all events names.

arc()

Short-hand for setting the policy to Arc

build(): Cache<K, V>

Builds a Cache or LoadingCache instance based on the options specified with this builder.

build(loader: LoaderFunction<K, V>): LoadingCache<K, V>
capacity(capacity: number)

Specifies the maximum number of entries the cache may contain.

events(options?: EventOptions)

Enables events via an EventEmitter.

lfu()

Short-hand for setting the policy to Lfu

lru()

Short-hand for setting the policy to Lru

policy(policy: Policy<K, V>)

Sets the caching strategy to the specified policy.

Registers a RemoveListener function. For cache removals.

sc()

Short-hand for setting the policy to SecondChance

Enables statistics collection during cache operations.

Short-hand for setting the policy to WindowTinyLfu

ttl(timeout: number, options?: ExpireOptions)

Specifies the time-to-live for cache entries. Takes optional ExpireOptions to specify when to refresh the TTL. By default it is never refreshed.

withEvent(name: EventName, active?: boolean)

Enables a specific event name.

Static Methods

builder<K1 extends Key, V1>()

Constructs a new Velo builder instance with default settings.

from<K1 extends Key, V1>(options: Options<K1, V1>)

Constructs a new Velo builder instance with given options applied.