Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface IExpirationCache<T>

preview

This API is in preview and not ready for production use. Expect breaking changes in the future. Class for implementing item caches with a time-based expiration.

template

T Cache item type

Type parameters

  • T

Hierarchy

  • IExpirationCache

Index

Methods

addOrUpdate

  • addOrUpdate(key: string, value: T, insertedAt?: number): void
  • Adds an item to the cache or updates the exiting cache item

    description

    This will refresh the expiration timer.

    Parameters

    • key: string

      Key to add

    • value: T

      Value to add

    • Optional insertedAt: number

    Returns void

get

  • get(key: string, markAsUsed?: boolean): T
  • Returns an item from the cache with the given key

    Parameters

    • key: string

      Key to retrieve

    • Optional markAsUsed: boolean

    Returns T

    Cache item

has

  • has(key: string): boolean
  • Checks if an item with the given key is in the cache and not expired

    Parameters

    • key: string

      Key to check

    Returns boolean

    Boolean indicating if a cache item with that ID exists

howOld

  • howOld(key: string): number | undefined
  • Checks if an item with the given key is in the cache and not expired

    Parameters

    • key: string

      Key to check

    Returns number | undefined

    undefined if it doesn't exist, otherwise how old the cache entry is in milliseconds

tryRemove

  • tryRemove(key: string, fireEvictionEvent?: boolean): boolean
  • Tries to remove an item from the cache with the given key, if it exists, and the removal is approved by event handlers

    Parameters

    • key: string

      Key to remove

    • Optional fireEvictionEvent: boolean

    Returns boolean

    Whether an item was removed

updateMaxSize

  • updateMaxSize(newMaxSize: number): void
  • Updates the max cache size

    Parameters

    • newMaxSize: number

      new max cache size

    Returns void