Options
All
  • Public
  • Public/Protected
  • All
Menu

Class InMemoryCache

Customized in-memory cache with LRU implemented

member

cacheObj - object which store items

member

cacheList - list of keys in the cache with LRU

member

curSizeInBytes - current size of the cache

member

maxPriority - max of the priority

member

cacheSizeLimit - the limit of cache size

Hierarchy

Implements

  • any

Index

Constructors

constructor

Properties

Protected cacheCurSizeKey

cacheCurSizeKey: string

Protected config

config: CacheConfig

Methods

clear

  • clear(): void

configure

createInstance

Protected fillCacheItem

getAllKeys

  • getAllKeys(): string[]

getCacheCurSize

  • getCacheCurSize(): number

getItem

  • Get item from cache. It will return null if item doesn’t exist or it has been expired. If you specified callback function in the options, then the function will be executed if no such item in the cache and finally put the return value into cache. Please make sure the callback function will return the value you want to put into the cache. The cache will abort output a warning: If the key is invalid

    Parameters

    • key: string

      the key of the item

    • Optional options: CacheItemOptions

      the options of callback function

    Returns any

getModuleName

  • getModuleName(): string

removeItem

  • removeItem(key: string): void

setItem

  • setItem(key: string, value: any | string | number | boolean, options?: CacheItemOptions): void
    • Set item into cache. You can put number, string, boolean or object. The cache will first check whether has the same key. If it has, it will delete the old item and then put the new item in The cache will pop out items if it is full You can specify the cache item options. The cache will abort and output a warning: If the key is invalid If the size of the item exceeds itemMaxSize. If the value is undefined If incorrect cache item configuration If error happened with browser storage
    throws

    if the item is too big which exceeds the limit of single item size

    throws

    if the key is invalid

    Parameters

    • key: string

      the key of the item

    • value: any | string | number | boolean

      the value of the item

    • Optional options: CacheItemOptions

      optional, the specified meta-data

    Returns void