Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MemCacheLRU

An in-memory LRU cache, implemented using a doubly-linked list.

example
import { MemCacheLRUBinning, toGibibytes } from "mega-cache";

const maxDataSize = toGibibytes(1);

let cache = new MemCacheLRU(
  maxDataSize // defaults to 150MiB
);
cache.set("key", Buffer.from("value"));
cache.get("key").toString(); //=> "value"

cache.get(cache.tail).toString() //=> "value"
cache.pop() //=> "key"
cache.pop() //=> undefined

Hierarchy

  • MemCacheLRU

Implements

Index

Constructors

constructor

  • Parameters

    • Default value maxDataSize: number = toMebibytes(150)

      The cache is limited to this data size. Setting large values is potentially O(n), where n is the number of objects which must be removed to make room for the new value. Setting a value that is too large for the cache is O(n) and will result in an error being throw. For performance, you should protect against this in your code.

    Returns MemCacheLRU

Properties

backwardsLinks

backwardsLinks: MegaHash

cacheType

cacheType: "sync" = "sync"

forwardsLinks

forwardsLinks: MegaHash

hashTable

hashTable: MegaHash

Optional head

head: Buffer

maxDataSize

maxDataSize: number

Optional tail

tail: Buffer

Accessors

count

  • get count(): any
  • Returns any

dataSize

  • get dataSize(): any
  • Returns any

Methods

[Symbol.iterator]

  • [Symbol.iterator](): Generator<Buffer, void, unknown>
  • Returns Generator<Buffer, void, unknown>

_pop

  • _pop(): Buffer | undefined
  • Returns Buffer | undefined

close

  • close(): void | Promise<void>
  • Returns void | Promise<void>

delete

  • delete(key: string | Buffer): void | Promise<void>
  • Parameters

    • key: string | Buffer

    Returns void | Promise<void>

get

  • get(key: Buffer | string): Buffer | undefined
  • Parameters

    • key: Buffer | string

    Returns Buffer | undefined

pop

  • pop(): undefined | string
  • Returns undefined | string

set

  • set(key: Buffer | string, value: Buffer): boolean
  • Parameters

    • key: Buffer | string
    • value: Buffer

    Returns boolean

shiftKeyToHead

  • shiftKeyToHead(key: Buffer): void
  • Parameters

    • key: Buffer

    Returns void

Generated using TypeDoc