getItem(key)
Returns an item.
Arguments
key(string): Key to get an item by.
Lifecycle
preGetItem
Event name:
preGetItemProperties passed:cacheInstancereference to cache instance (this)keykey passed togetItemmethod
Returns: (object): object containing properties:
cacheInstancereference to cache instance (this)keykey passed through handlers added forpreGetItemevent
postGetItem
Event name:
postGetItemProperties passed:cacheInstancereference to cache instance (this) returned bypreGetItemkeykey returned bypreGetItemitemitem returned by adapter using its getItem method
Returns: (object): object containing properties:
cacheInstancereference to cache instance (this)keykey passed through handlers added forpostGetItemeventitemitem passed through handlers added forpostGetItemevent
Eventually
getItemreturns item returned bypostGetItem.
Even though getItem uses buildKey internally that build key is not passed in postGetItem event handler's object's properties. If key is somehow changed (with some plugin) during preBuildKey or postGetKey events, that key is not passed further in getItem. If you need access to built key, you can still obtain it from returned item to which you have access in postGetItem.
Make sure that item exists when writing plugins, always. When item is passed to event handler for this event, it might not be an actual item, but undefined. Why? Some plugin before one you will use to operate on this item, might have already removed it. 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 item's data,
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 accessvalueor anything from that item, your app will crash.
Returns
(Item): Item, an object.
(undefined): If item is not found, returns undefined.
Example
Last updated