Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Cache<T>

use to cache something

Type parameters

  • T

Hierarchy

  • Cache

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

  • newCache(map?: Record<string, T>): Cache

Properties

Private _count

_count: number = 0

Private _map

_map: Record<string, T> | null = null

Accessors

count

  • get count(): number

Methods

add

  • add(key: string, val: T): T
  • Add Key-Value to cache

    example

    var cache = new Cache(); cache.add('test', null);

    Parameters

    • key: string

      The key

    • val: T

      The value

    Returns T

    The value

clear

  • clear(): void

destroy

  • destroy(): void

find

  • find(predicate: (val: T, key: string) => boolean): T | null
  • Enumerate all content to find one element which can fulfill condition

    example

    var cache = new Cache(); var val = cache.find((val, key) => key === 'test');

    Parameters

    • predicate: (val: T, key: string) => boolean

      The condition

        • (val: T, key: string): boolean
        • Parameters

          • val: T
          • key: string

          Returns boolean

    Returns T | null

    content

forEach

  • forEach(func: (val: T, key: string) => void): void
  • Enumerate all content and invoke function

    example

    var cache = new Cache(); cache.forEach((val, key) => console.log(key));

    Parameters

    • func: (val: T, key: string) => void

      Function to be invoked

        • (val: T, key: string): void
        • Parameters

          • val: T

            The value

          • key: string

            The corresponding key

          Returns void

    Returns void

get

  • get(key: string): T | undefined
  • Get the cached content by key

    example

    let cache = new Cache(); let test = cache.get('test');

    Parameters

    • key: string

      The key

    Returns T | undefined

    The corresponding content

has

  • has(key: string): boolean
  • Check whether or not content exists by key

    example

    var cache = new Cache(); var exist = cache.has('test');

    Parameters

    • key: string

      The key

    Returns boolean

    True indecates that content of the key exists

remove

  • remove(key: string): T | undefined
  • Remove the cached content by key

    example

    var cache = new Cache(); var content = cache.remove('test');

    Parameters

    • key: string

      The key

    Returns T | undefined

    The removed content

Generated using TypeDoc