Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CacheManager

The cache manager provides simple key-value storage at a high-speed data storage layer (Redis) speeding up data set and get operations.

The values stored can be a single JSON object, an array of objects or primitive values (e.g., numbes, text, boolean). Values can be stored with an optional time-to-live (TTL) to automatically expire entries.

You can directly store primitive values such as integers, strings, etc., however, when you try to get them Altogic returns them wrapped in a simple object with a key named value. As an example if you store a text field "Hello world!" at a key named 'welcome', when you try to get the value of this key using the get method, you will receive the following response: { value: "Hellow world"}.

export

Hierarchy

Index

Constructors

Properties

fetcher: Fetcher

The http client to make RESTful API calls to the application's execution engine

Methods

  • decrement(key: string, decrement?: number, ttl?: number): Promise<{ data: null | object; errors: null | APIError }>
  • Decrements the value of the number stored at the key by the decrement amount. If decrement amount not specified, decrements the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation. If ttl specified, sets the stored entry to automatically expire in specified seconds. Any previous time to live associated with the key is discarded on successful decrement operation.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • key: string

      The key to decrement

    • decrement: number = 1
    • Optional ttl: number

      Time to live in seconds

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns the value of key after the decrement

  • delete(keys: string | string[]): Promise<{ errors: null | APIError }>
  • Removes the specified key(s) from the cache. Irrespective of whether the key is found or not, success response is returned.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • keys: string | string[]

      A single key or an array of keys (string) to delete

    Returns Promise<{ errors: null | APIError }>

  • expire(key: string, ttl: number): Promise<{ errors: null | APIError }>
  • Sets a timeout on key. After the timeout has expired, the key will automatically be deleted.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • key: string

      The key to set its expiry duration

    • ttl: number

      Time to live in seconds

    Returns Promise<{ errors: null | APIError }>

  • get(key: string): Promise<{ data: null | object | object[]; errors: null | APIError }>
  • Gets an item from the cache by key. If key is not found, then null is returned as data.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • key: string

      The key to retrieve

    Returns Promise<{ data: null | object | object[]; errors: null | APIError }>

  • getStats(): Promise<{ data: null | object; errors: null | APIError }>
  • Returns the overall information about your apps cache including total number of keys and total storage size (bytes), daily and monthly ingress and egress volumes (bytes).

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns information about your app's cache storage

  • increment(key: string, increment?: number, ttl?: number): Promise<{ data: null | object; errors: null | APIError }>
  • Increments the value of the number stored at the key by the increment amount. If increment amount not specified, increments the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation. If ttl specified, sets the stored entry to automatically expire in specified seconds. Any previous time to live associated with the key is discarded on successful increment operation.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • key: string

      The key to increment

    • increment: number = 1
    • Optional ttl: number

      Time to live in seconds

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns the value of key after the increment

  • listKeys(pattern?: string, next?: string): Promise<{ data: null | object[]; errors: null | APIError; next: null | string }>
  • Gets the list of keys in your app cache storage. If pattern is specified, it runs the pattern match to narrow down returned results, otherwise, returns all keys contained in your app's cache storage. See below examples how to specify filtering pattern:

    • h?llo matches hello, hallo and hxllo
    • h*llo matches hllo and heeeello
    • h[ae]llo matches hello and hallo, but not hillo
    • h[^e]llo matches hallo, hbllo, ... but not hello
    • h[a-b]llo matches hallo and hbllo

    You can paginate through your cache keys using the next cursor. In your first call to listKeys, specify the next value as null. This will start pagination of your cache keys. In the return result of the method you can get the list of keys matching your pattern and also the next value that you can use in your next call to listKeys method to move to the next page. If the returned next value is null this means that you have paginated all your keys and there is no additional keys to paginate.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • Optional pattern: string

      The pattern string that will be used to filter cache keys

    • Optional next: string

      The next page position cursor to paginate to the next page. If set as null or undefined, starts the pagination from the beginning.

    Returns Promise<{ data: null | object[]; errors: null | APIError; next: null | string }>

    Returns the array of matching keys, their values and the next cursor if there are remaining items to paginate.

  • set(key: string, value: any, ttl?: number): Promise<{ errors: null | APIError }>
  • Sets an item in the cache. Overwrites any existing value already set. If ttl specified, sets the stored entry to automatically expire in specified seconds. Any previous time to live associated with the key is discarded on successful set operation.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • key: string

      The key to update

    • value: any

      The value to set

    • Optional ttl: number

      Time to live in seconds

    Returns Promise<{ errors: null | APIError }>

Generated using TypeDoc