setExtra(key, extra)

Sets (replaces whole existing) extra in an item.

As existing extra is being entirely overwritten, be careful how / when you use it. Simply, use this method with caution.

Arguments

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

  2. extra (object): Extra data to replace existing one.

Throws

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

Lifecycle

  1. preSetExtra

    Event name: preSetExtra Properties passed:

    • cacheInstance reference to cache instance (this)

    • key key passed to setExtra method

    • extra extra passed to setExtra method

    Returns: (object): object containing properties:

    • cacheInstance reference to cache instance (this)

    • key key passed through handlers added for preSetExtra event

    • extra extra passed through handlers added for preSetExtra event

  2. postSetExtra

    Event name: postSetExtra Properties passed:

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

    • key key returned by preSetExtra

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

    Returns: (object): object containing properties:

    • cacheInstance reference to cache instance (this)

    • key key passed through handlers added for postSetExtra event

    • extra extra passed through handlers added for postSetExtra event

    Eventually setExtra returns extra returned by postSetExtra.

Example

// Existing extra
{ 
    some: 'data'
}

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

// Extra after setting new one
{
    foo: 'bar'
}

Last updated