getExtra(key)
Returns extra (for given object for given key).
Arguments
key
(string): Key to get an extra by.
Lifecycle
preGetExtra
Event name:
preGetExtra
Properties passed:cacheInstance
reference to cache instance (this
)key
key passed togetExtra
method
Returns: (object): object containing properties:
cacheInstance
reference to cache instance (this
)key
key passed through handlers added forpreGetExtra
event
postGetExtra
Event name:
postGetExtra
Properties passed:cacheInstance
reference to cache instance (this
) returned bypreGetExtra
key
key returned bypreGetExtra
extra
extra (object) returned by adapter using its getExtra method
Returns: (object): object containing properties:
cacheInstance
reference to cache instance (this
)key
key passed through handlers added forpostGetExtra
eventextra
extra passed through handlers added forpostGetExtra
event
Eventually
getExtra
returns extra returned bypostGetExtra
.
Even though getExtra
uses buildKey
internally, that build key is not passed in postGetExtra
event handler's object's properties. If key is somehow changed (using some plugin) during preBuildKey
or postGetKey
events, that key is not passed further in getExtra
. If you need access to built key, you can still obtain it from returned item to which you have access in postGetExtra
.
Make sure that extra
exists when writing plugins, always. When extra
is passed to event handler for this event, it might not exist anymore, and be undefined
. Why? Some plugin before one you will use to operate on this extra, might have already removed item (from which this extra is taken from). How? Here's an example:
you have a ttl plugin that will automatically remove an item once it's lifetime is over,
you have another plugin that does something with this item's extra,
order of executing plugins matter, therefore when first plugin will remove that item and pass
undefined
further down, every next plugin will operate on that undefined value. So do not try to access any property from that extra, your app will crash.
Returns
(object): Object, extra from item.
(undefined): If item is not found (thus no extra can be taken from it), returns undefined
.
Example
Last updated