Skip to content

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

StorageUnderlyingDefault
Storage.idbIndexedDBin browser environments
Storage.cookieCookie
Storage.localStoragelocalStorage
Storage.memoryJavaScript Mapin 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())
})