Persistence

Persistence

DataSources provide basic volatile persistence by default. The last 10k events will be stored in memory (RAM) and will be queryable.

If you don't know what a DataSource is, read this guide first

MessageDataSources can have their default transport-manager side storage modified by setting the setPersistenceEngineFactory method on the QueryableMessageIDProvider.

ts
// template/src/transport-manager/index.tsx
import {
DataSource,
PersistenceEngineMemory,
} from '@electricui/core-timeseries'
 
queryableMessageIDProvider.setPersistenceEngineFactory(
'speed',
(dataSource: DataSource) => {
// Use the in-memory persistence engine with a ceiling of 20k points
return new PersistenceEngineMemory(20_000)
},
)

Note

As the PersistenceEngineMemory allocates storage for the message based on the ceiling value per-device, applications which handle frequently changing devices or large meshes should be aware of the memory impact of deep storage pools.

Allocated space = eventSize * maxItems * number of unique devices that have connected

If no persistence is desired, the PersistenceEnginePassthrough engine can be used which does no buffering.

ts
import {
DataSource,
PersistenceEnginePassthrough,
} from '@electricui/core-timeseries'
// template/src/transport-manager/index.tsx
 
queryableMessageIDProvider.setPersistenceEngineFactory(
'speed',
(dataSource: DataSource) => {
// No storage, events are streamed through the entire system
return new PersistenceEnginePassthrough()
},
)

Custom DataSources

DataSources can have their default storage modified by setting the setPersistenceEngineFactory method on the dataSource itself.

ts
import {
DataSource,
PersistenceEngineMemory,
} from '@electricui/core-timeseries'
 
const customDataSource = new DataSource()
customDataSource.setPersistenceEngineFactory(
dataSource => new PersistenceEngineMemory(20_000),
)