hasItem(key)

Checks if item exists.

Arguments

  1. key (string): Key to check if an item exists by.

Lifecycle

  1. preHasItem

    Event name: preHasItem Properties passed:

    • cacheInstance reference to cache instance (this)

    • key key passed to hasItem method

    Returns: (object): object containing properties:

    • cacheInstance reference to cache instance (this)

    • key key passed through handlers added for preHasItem event

  2. postHasItem

    Event name: postHasItem Properties passed:

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

    • key key returned by preHasItem

    • result boolean value returned by adapter using its hasItem method

    Returns: (object): object containing properties:

    • cacheInstance reference to cache instance (this)

    • key key passed through handlers added for postHasItem event

    • result boolean value passed through handlers added for postHasItem event

    Eventually hasItem returns result returned by postHasItem.

Even though hasItem uses buildKey internally, that build key is not passed in postHasItem event handler's object's properties. If key is somehow changed (with some plugin) during preBuildKey or postGetKey event handlers, that key is not passed further in hasItem. If you need access to built key, you can still obtain it from returned item to which you have access in postHasItem.

Returns

(bool): true if item exists, false otherwise.

Example

// assuming that you already have cache instance prepared
cache.hasItem('key'); // true
cache.hasItem('keyForItemThatDoesNotExist'); // false

Last updated