Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Storage<TValue>

The main interface of the library. Capable of caching, saving and loading storage data

Type parameters

  • TValue

Hierarchy

  • Storage

Index

Constructors

constructor

Properties

Readonly key

key: Buffer

The key used for encrypting the log file and storage file

Readonly options

The options for this storage instance

Accessors

size

  • get size(): number
  • The size of the storage's cache

    Returns number

Methods

clear

  • clear(): Promise<void>
  • Clears the cached data in the storage

    Returns Promise<void>

getItem

  • getItem<T>(key: string): T | null
  • Returns an item identified by its key if exists, otherwise returns null

    Type parameters

    • T: TValue

    Parameters

    • key: string

      The key of the item

    Returns T | null

hasItem

  • hasItem(key: string): boolean
  • Whether this storage contains an item

    Parameters

    • key: string

      The key of the item

    Returns boolean

load

  • load(): Promise<this>
  • Load all data from the logs and saved JSON

    Returns Promise<this>

loadJSON

  • loadJSON(): Promise<void>
  • Loads all items inside the JSON file onto the cache

    Returns Promise<void>

removeItem

  • removeItem(key: string, log?: boolean): Promise<void>
  • Removes an item from the storage

    Parameters

    • key: string

      The key of the item

    • Default value log: boolean = true

      Whether to log the removed item

    Returns Promise<void>

saveJSON

  • saveJSON(): Promise<void>
  • Saves the cache to the JSON file

    Returns Promise<void>

setItem

  • setItem<T>(key: string, value: T, log?: boolean): Promise<void>
  • Adds an item identified by a key to the storage

    Type parameters

    • T: TValue

    Parameters

    • key: string

      The identifier of the item

    • value: T

      The item value

    • Default value log: boolean = true

      Whether to log the pair item to the log file

    Returns Promise<void>

toJSON

  • toJSON(): Record<string, TValue>
  • Converts the cached map into JSON

    Returns Record<string, TValue>

Generated using TypeDoc