getItem(key)

Returns an item.

Arguments

  1. key (string): Key to get an item by.

Lifecycle

  1. preGetItem

    Event name: preGetItem Properties passed:

    • cacheInstance reference to cache instance (this)

    • key key passed to getItem method

    Returns: (object): object containing properties:

    • cacheInstance reference to cache instance (this)

    • key key passed through handlers added for preGetItem event

  2. postGetItem

    Event name: postGetItem Properties passed:

    • cacheInstance reference to cache instance (this) returned by preGetItem

    • key key returned by preGetItem

    • item item returned by adapter using its getItem method

    Returns: (object): object containing properties:

    • cacheInstance reference to cache instance (this)

    • key key passed through handlers added for postGetItem event

    • item item passed through handlers added for postGetItem event

    Eventually getItem returns item returned by postGetItem.

Returns

(Item): Item, an object.

(undefined): If item is not found, returns undefined.

Example

// assuming that you already have cache instance prepared
cache.getItem('key'); // Item
cache.getItem('keyForItemThatDoesNotExist'); // undefined

Last updated