addExtra(key, extra)
Adds extra to item's existing extra. New properties are added, existing are overwritten.
Arguments
key
(string): Key to store the extra under (represents given item).extra
(object): Extra data to store.
Throws
If
extra
is not an object, it will throw'extra' must be an object.
Lifecycle
preAddExtra
Event name:
preAddExtra
Properties passed:cacheInstance
reference to cache instance (this
)key
key passed toaddExtra
methodextra
extra passed toaddExtra
method
Returns: (object): object containing properties:
cacheInstance
reference to cache instance (this
)key
key passed through handlers added forpreAddExtra
eventextra
extra passed through handlers added forpreAddExtra
event
postAddExtra
Event name:
postAddExtra
Properties passed:cacheInstance
reference to cache instance (this
) returned bypreAddExtra
key
key returned bypreAddExtra
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 forpostAddExtra
eventextra
extra passed through handlers added forpostAddExtra
event
Eventually
addExtra
returns extra returned bypostAddExtra
.
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