getItem(key)
Returns an item.
Arguments
key
(string): Key to get an item by.
Lifecycle
preGetItem
Event name:
preGetItem
Properties passed:cacheInstance
reference to cache instance (this
)key
key passed togetItem
method
Returns: (object): object containing properties:
cacheInstance
reference to cache instance (this
)key
key passed through handlers added forpreGetItem
event
postGetItem
Event name:
postGetItem
Properties passed:cacheInstance
reference to cache instance (this
) returned bypreGetItem
key
key returned bypreGetItem
item
item returned by adapter using its getItem method
Returns: (object): object containing properties:
cacheInstance
reference to cache instance (this
)key
key passed through handlers added forpostGetItem
eventitem
item passed through handlers added forpostGetItem
event
Eventually
getItem
returns 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
undefined
further down, every next plugin will operate on that undefined value. So do not try to accessvalue
or anything from that item, your app will crash.
Returns
(Item): Item, an object.
(undefined): If item is not found, returns undefined
.
Example
Last updated