The cache.

Implements

Constructors

  • Constructs a cache.

    Parameters

    • opts: {
          byteCapacity?: number;
          maxNumberOfEntries?: number;
          ttl?: number;
      } = ...

      The options.

      • Optional byteCapacity?: number

        The capacity, in bytes, of the cache.

      • Optional maxNumberOfEntries?: number

        The capacity, in number of entries, of the cache.

      • Optional ttl?: number

        The default TTL (time to live) of entries. Can be overriden for each entry (see CacheOptions).

    Returns Cache

Properties

isMemoryUsage: true = ...

Accessors

  • get capacity(): number
  • Gets the maximum number of entries.

    Returns number

  • get count(): number
  • Gets the number of entries.

    Returns number

  • get defaultTtl(): number
  • Gets or sets the default TTL (time to live) of the cache.

    Returns number

  • set defaultTtl(v): void
  • Parameters

    • v: number

    Returns void

  • get enabled(): boolean
  • Enables or disables the cache.

    Returns boolean

  • set enabled(v): void
  • Parameters

    • v: boolean

    Returns void

  • get maxSize(): number
  • Gets the maximum size of the cache, in bytes.

    Returns number

  • get size(): number
  • Gets the size of entries, in bytes

    Returns number

Methods

  • Deletes an entry.

    Parameters

    • key: string

      The key.

    Returns boolean

    true if the entry was deleted, false otherwise.

  • Returns an array of entries.

    Returns unknown[]

  • Returns the entry with the specified key, or undefined if no entry matches this key.

    Parameters

    • key: string

      The entry key.

    Returns unknown

    The entry, or undefined.

  • Stores an entry in the cache, or replaces an existing entry with the same key.

    Parameters

    • key: string

      The key.

    • value: object

      The value.

    • options: CacheOptions = {}

      The options.

    Returns object