Customized storage based on the SessionStorage or LocalStorage with LRU implemented

Hierarchy (view full)

Implements

Constructors

Properties

config: CacheConfig
keyValueStorage: KeyValueStorageInterface
storage: Storage

Methods

  • clear the entire cache The cache will abort and output a warning if error occurs

    Returns Promise<void>

  • Return a new instance of cache with customized configuration.

    Parameters

    Returns Cache

    • the new instance of Cache
  • produce a JSON object with meta-data and data value

    Parameters

    • key: string
    • value: string | number | boolean | object

      the value of the item

    • options: CacheItemOptions

      optional, the specified meta-data

    Returns CacheItem

    • the item which has the meta-data and the value
  • Parameters

    • Optional options: {
          omitSizeKey?: boolean;
      }
      • Optional omitSizeKey?: boolean

    Returns Promise<string[]>

  • Return all the keys owned by this cache. Will return an empty array if error occurred.

    Returns Promise<string[]>

  • 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 If error happened with AsyncStorage

    Parameters

    • key: string

      the key of the item

    • Optional options: CacheItemOptions

      the options of callback function

    Returns Promise<any>

    • return a promise resolves to be the value of the item
  • check whether item is expired

    Parameters

    • key: string

      the key of the item

    Returns Promise<boolean>

    true if the item is expired.

  • delete item from cache

    Parameters

    • prefixedKey: string

      the key of the item

    • Optional size: number

      optional, the byte size of the item

    Returns Promise<void>

  • remove item from the cache The cache will abort output a warning: If error happened with AsyncStorage

    Parameters

    • key: string

      the key of the item

    Returns Promise<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

    Parameters

    • key: string

      the key of the item

    • value: any

      the value of the item

    • Optional options: Record<string, any>

      optional, the specified meta-data

    Returns Promise<void>