set

Add the key to the storage, or update that key's value if it already exist

set(key, value, options)

Parameters

key
{string} name of the key you want to create or update
value
{mixed} name of the key you want to create or update. Must be a string, int, float, array, object...
options
{object} add options for storage if necessary

Options

expire

If you want your data expires, add expire in option parameter.
The value of expire must be expressed in second.
By default the value is false

readonly

If you want your data is neither modified nor deleteable., add readonly in option parameter.
The value of readonly must be a boolean.
By default the value is false

Return

This method return a boolean

Exemples

// String with LocalStorage

OhMyCache.Local.set('key', 'value')

// String with SessionStorage

OhMyCache.Session.set('key', 'value')

// Array

OhMyCache.Local.set('key', [1,2,3])

// Object

OhMyCache.Local.set('user', {fistname: 'James', lastname: 'Bond'})

// With expiration

OhMyCache.Local.set('key', 'value', {expire: 3600}) // data expires in 1 hour


// ReadOnly

OhMyCache.Local.set('key', 'value', {readonly: true}) // return true

OhMyCache.Local.set('key', 'change') // return false

OhMyCache.Local.get('key') // return 'value'