Storage
Porto comes pre-configured with a storage layer suited for both browser and non-browser environments.
By default, Porto uses IndexedDB in browser environments and an in-memory KV store in non-browser environments.
Storage Backends
Storage | Underlying | Default |
---|---|---|
Storage.idb | IndexedDB | in browser environments |
Storage.cookie | Cookie | |
Storage.localStorage | localStorage | |
Storage.memory | JavaScript Map | in non-browser environments |
Usage
Storage.idb
import { Porto, Storage } from 'porto'
const porto = Porto.create({
storage: Storage.idb() // default storage in browser environments
})
Storage.cookie
import { Porto, Storage } from 'porto'
const porto = Porto.create({
storage: Storage.cookie()
})
Storage.localStorage
import { Porto, Storage } from 'porto'
const porto = Porto.create({
storage: Storage.localStorage()
})
Storage.memory
import { Porto, Storage } from 'porto'
const porto = Porto.create({
storage: Storage.memory() // default storage in non-browser environments
})
Combining multiple storage options
import { Porto, Storage } from 'porto'
const porto = Porto.create({
storage: Storage.combine(Storage.cookie(), Storage.localStorage())
})