Skip to main content

Overview

The Storage Service provides an abstract interface for storing and retrieving data across different storage backends. It supports various storage locations (disk, memory, session) and optional secure storage encryption.

StorageService

The base abstract class that all storage implementations must extend.

Interface

Properties

valuesRequireDeserialization

Indicates whether values stored in this storage service require deserialization when retrieved.

Methods

get<T>()

Retrieves a value from storage. Parameters:
  • key (string): The storage key to retrieve
  • options (StorageOptions, optional): Configuration options for the storage operation
Returns: Promise<T> - The stored value, typed according to the generic parameter Example:

has()

Checks whether a key exists in storage. Parameters:
  • key (string): The storage key to check
  • options (StorageOptions, optional): Configuration options for the storage operation
Returns: Promise<boolean> - True if the key exists, false otherwise Example:

save<T>()

Saves a value to storage. Parameters:
  • key (string): The storage key to save under
  • obj (T): The value to store
  • options (StorageOptions, optional): Configuration options for the storage operation
Returns: Promise<void> Example:

remove()

Removes a value from storage. Parameters:
  • key (string): The storage key to remove
  • options (StorageOptions, optional): Configuration options for the storage operation
Returns: Promise<void> Example:

ObservableStorageService

An interface that extends storage services with observable update streams.

Interface

Properties

updates$

Provides an observable stream of storage updates that have occurred in this storage service or in the underlying storage backend. Returns: Observable<StorageUpdate> - Stream of storage update events Example:

Types

StorageOptions

Configuration options for storage operations. Properties:
  • storageLocation (StorageLocation, optional): The location where data should be stored (disk, memory, or both)
  • useSecureStorage (boolean, optional): Whether to use encrypted secure storage
  • userId (string, optional): User ID to scope the storage key to a specific user
  • htmlStorageLocation (HtmlStorageLocation, optional): HTML5 storage location (local, session, or memory)
  • keySuffix (string, optional): Suffix to append to the storage key

StorageUpdate

Represents a storage update event. Properties:
  • key (string): The storage key that was updated
  • updateType (StorageUpdateType): The type of update that occurred

StorageUpdateType

The type of storage update operation.

StorageLocation

Specifies where data should be persisted.
  • Both: Store in both disk and memory
  • Disk: Store on disk for persistence across sessions
  • Memory: Store in memory only (cleared on restart)

HtmlStorageLocation

Specifies HTML5 storage location for browser-based implementations.
  • Local: Use localStorage (persists across sessions)
  • Memory: Use in-memory storage (cleared on page reload)
  • Session: Use sessionStorage (persists for session only)

Usage Examples

Basic Storage Operations

Using Storage Options

Observing Storage Updates