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:
preSetItem
Properties passed:cacheInstance
reference to cache instance (this
)key
key passed tosetItem
methodvalue
value passed tosetItem
methodextra
extra passed tosetItem
method
Returns: (object): object containing properties:
cacheInstance
reference to cache instance (this
)key
key passed through handlers added forpreSetItem
eventvalue
value passed through handlers added forpreSetItem
eventextra
extra passed through handlers added forpreSetItem
event
postSetItem
Event name:
postSetItem
Properties passed:cacheInstance
reference to cache instance (this
) returned bypreSetItem
key
key returned bypreSetItem
value
value returned bypreSetItem
extra
extra returned bypreSetItem
item
returned by adapter using setItem method
Returns: (object): object containing properties:
cacheInstance
reference to cache instance (this
)key
key passed through handlers added forpostSetItem
eventvalue
value passed through handlers added forpostSetItem
eventextra
extra passed through handlers added forpostSetItem
eventitem
item passed through handlers added forpostSetItem
event
Eventually
setItem
returns 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