Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MemoryCache

Cache that stores values in the process memory.

Remember: This implementation is not suitable for synchronization of distributed processes.

Configuration parameters

options:

  • timeout: default caching timeout in milliseconds (default: 1 minute)
  • max_size: maximum number of values stored in this cache (default: 1000)
see

ICache

Example

let cache = new MemoryCache();

cache.store("123", "key1", "ABC", (err) => {
    cache.store("123", "key1", (err, value) => {
        // Result: "ABC"
    });
});

Hierarchy

  • MemoryCache

Implements

Index

Constructors

Methods

Constructors

constructor

Methods

configure

  • configure(config: ConfigParams): void
  • Configures component by passing configuration parameters.

    Parameters

    • config: ConfigParams

      configuration parameters to be set.

    Returns void

remove

  • remove(correlationId: string, key: string, callback: function): void
  • Removes a value from the cache by its key.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • key: string

      a unique value key.

    • callback: function

      (optional) callback function that receives an error or null for success

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

retrieve

  • retrieve(correlationId: string, key: string, callback: function): void
  • Retrieves cached value from the cache using its key. If value is missing in the cache or expired it returns null.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • key: string

      a unique value key.

    • callback: function

      callback function that receives cached value or error.

        • (err: any, value: any): void
        • Parameters

          • err: any
          • value: any

          Returns void

    Returns void

store

  • store(correlationId: string, key: string, value: any, timeout: number, callback: function): void
  • Stores value in the cache with expiration time.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • key: string

      a unique value key.

    • value: any

      a value to store.

    • timeout: number

      expiration timeout in milliseconds.

    • callback: function

      (optional) callback function that receives an error or null for success

        • (err: any, value: any): void
        • Parameters

          • err: any
          • value: any

          Returns void

    Returns void

Generated using TypeDoc