Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Cache<T>

用于缓存某些内容

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
  • 增加键值对到缓存中

    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
  • 枚举所有内容,找到一个可以满足条件的元素

    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
  • 枚举所有内容并执行方法

    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
  • 通过 key 获取对应的 value

    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
  • 通过 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
  • 通过 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