setItem(key, value, [extra])
Sets an item (and returns it, once created).
Arguments
key(string): Key to store the value under.value(any): Any value to store in item. See values.extra(object): Optional, defaults to empty object if not passed. Extra data to store alongside value in item.
Lifecycle
preSetItem
Event name:
preSetItemProperties passed:cacheInstancereference to cache instance (this)keykey passed tosetItemmethodvaluevalue passed tosetItemmethodextraextra passed tosetItemmethod
Returns: (object): object containing properties:
cacheInstancereference to cache instance (this)keykey passed through handlers added forpreSetItemeventvaluevalue passed through handlers added forpreSetItemeventextraextra passed through handlers added forpreSetItemevent
postSetItem
Event name:
postSetItemProperties passed:cacheInstancereference to cache instance (this) returned bypreSetItemkeykey returned bypreSetItemvaluevalue returned bypreSetItemextraextra returned bypreSetItemitemreturned by adapter using setItem method
Returns: (object): object containing properties:
cacheInstancereference to cache instance (this)keykey passed through handlers added forpostSetItemeventvaluevalue passed through handlers added forpostSetItemeventextraextra passed through handlers added forpostSetItemeventitemitem passed through handlers added forpostSetItemevent
Eventually
setItemreturns item returned bypostSetItem.
Even though setItem uses buildKey internally, that built key is not passed in postSetItem event handler's object's properties. If key is somehow changed (with some plugin) during preBuildKey or postGetKey event handlers, that key is not passed further in setItem. If you need access to built key, you can still obtain it from returned item to which you have access in postSetItem.
Returns
(Item): Stored (thus created) item.
Example
Last updated