removeItem(key)

Removes an item.

Arguments

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

Lifecycle

  1. preRemoveItem

    Event name: preRemoveItem Properties passed:

    • cacheInstance reference to cache instance (this)

    • key key passed to removeItem method

    Returns: (object): object containing properties:

    • cacheInstance reference to cache instance (this)

    • key key passed through handlers added for preRemoveItem event

  2. postRemoveItem

    Event name: postRemoveItem Properties passed:

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

    • key key returned by preRemoveItem

    • result boolean value returned by adapter using its removeItem method

    Returns: (object): object containing properties:

    • cacheInstance reference to cache instance (this)

    • key key passed through handlers added for postRemoveItem event

    • result boolean value passed through handlers added for postRemoveItem event

    Eventually removeItem returns result returned by postRemoveItem.

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

Returns

(bool): true if item was removed, false otherwise.

Example

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

Last updated