Hierarchy

  • ICache

Methods

getItem

  • getItem(key: string): Promise<string | null>
  • Get a value from the server’s cache.

    Parameters

    • key: string

      Value key.

    Returns Promise<string | null>

    Value saved in the cache or null if nothing is found based on the key.

setItem

  • setItem(key: string, value: string, ttlInMs?: undefined | number): Promise<void>
  • Save the value to the server's cache.

    By default, data is stored in the cache for 30 seconds. To store it longer, set the storage time in the ttlInMs parameter. Note that caching data, even for a long period of time, does not guarantee that you will get it when you use the getItem method. To store data securely for a long time, use storage (IStorage).

    await Application.cache.setItem( 'key', JSON.stringify({ 'some_key' : 'some_data', 'arr' : [ 1, 2, 3 ] }));
    // When data needs to be requested 
    let value = await Application.cache. getItem('key'); 
    if (!value) { 
        // Getting the initial value based on  source data 
        value = await longOperation_initDefaultValue(); 
    } 
    

    Parameters

    • key: string

      Value key.

    • value: string

      Data to be saved.

    • Optional ttlInMs: undefined | number

      Storage period in milliseconds.

    Returns Promise<void>