addExtra(key, extra)

Adds extra to item's existing extra. New properties are added, existing are overwritten.

Arguments

  1. key (string): Key to store the extra under (represents given item).

  2. extra (object): Extra data to store.

Throws

  1. If extra is not an object, it will throw 'extra' must be an object.

Lifecycle

  1. preAddExtra

    Event name: preAddExtra Properties passed:

    • cacheInstance reference to cache instance (this)

    • key key passed to addExtra method

    • extra extra passed to addExtra method

    Returns: (object): object containing properties:

    • cacheInstance reference to cache instance (this)

    • key key passed through handlers added for preAddExtra event

    • extra extra passed through handlers added for preAddExtra event

  2. postAddExtra

    Event name: postAddExtra Properties passed:

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

    • key key returned by preAddExtra

    • extra extra (object) returned by adapter using its addExtra method

    Returns: (object): object containing properties:

    • cacheInstance reference to cache instance (this)

    • key key passed through handlers added for postAddExtra event

    • extra extra passed through handlers added for postAddExtra event

    Eventually addExtra returns extra returned by postAddExtra.

Example

// Existing extra in an item
{ 
    some: 'data'
}

cache.addExtra(key, { foo: 'bar' });

// Extra after adding new one
{
    foo: 'bar',
    some: 'data'
}

cache.addExtra(key, { foo: 'baz' });

// Extra after another round of adding stuff to it
{
    foo: 'baz', // <-- notice that this value's changed
    some: 'data'
}

Last updated