getExtra(key)
Returns extra (for given object for given key).
Arguments
key(string): Key to get an extra by.
Lifecycle
preGetExtra
Event name:
preGetExtraProperties passed:cacheInstancereference to cache instance (this)keykey passed togetExtramethod
Returns: (object): object containing properties:
cacheInstancereference to cache instance (this)keykey passed through handlers added forpreGetExtraevent
postGetExtra
Event name:
postGetExtraProperties passed:cacheInstancereference to cache instance (this) returned bypreGetExtrakeykey returned bypreGetExtraextraextra (object) returned by adapter using its getExtra method
Returns: (object): object containing properties:
cacheInstancereference to cache instance (this)keykey passed through handlers added forpostGetExtraeventextraextra passed through handlers added forpostGetExtraevent
Eventually
getExtrareturns 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
undefinedfurther 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