persist

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2025 License: AGPL-3.0 Imports: 7 Imported by: 10

Documentation

Overview

Package persist enables persistent storage of the execution state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Persister

type Persister struct {
	State  *state.State
	Memory *cache.Cache
	// contains filtered or unexported fields
}

Persister abstracts storage and retrieval of state and cache.

func NewPersister

func NewPersister(db db.Db) *Persister

NewPersister creates a new Persister instance.

func (*Persister) Deserialize

func (p *Persister) Deserialize(b []byte) error

Deserialize decodes the state and cache from storage, and applies them to the persister.

func (*Persister) GetMemory

func (p *Persister) GetMemory() cache.Memory

GetMemory returns the cache (memory) enclosed by the Persister.

func (*Persister) GetState

func (p *Persister) GetState() *state.State

GetState returns the state enclosed by the Persister.

func (*Persister) Invalid

func (p *Persister) Invalid() bool

Invalid checks if the underlying state has been invalidated.

An invalid state will cause Save to panic.

func (*Persister) Load

func (p *Persister) Load(key string) error

Load retrieves state and cache from the db.Db backend.

func (*Persister) Save

func (p *Persister) Save(key string) error

Save persists the state and cache to the db.Db backend.

If save is successful and WithFlush() has been called, the state and memory will be empty when the method returns.

func (*Persister) Serialize

func (p *Persister) Serialize() ([]byte, error)

Serialize encodes the state and cache into byte form for storage.

func (*Persister) String added in v0.2.0

func (p *Persister) String() string

String implements the String interface

func (*Persister) WithContent

func (p *Persister) WithContent(st *state.State, ca *cache.Cache) *Persister

WithContent is a chainable function that sets a current State and Cache object.

This method is normally called before Serialize / Save.

func (*Persister) WithContext

func (p *Persister) WithContext(ctx context.Context) *Persister

WithSession is a chainable function that sets the current golang context of the persister.

func (*Persister) WithFlush

func (p *Persister) WithFlush() *Persister

WithFlush is a chainable function that instructs the persister to flush its memory and state after successful Save.

func (*Persister) WithSession

func (p *Persister) WithSession(sessionId string) *Persister

WithSession is a chainable function that sets the current session context of the persister.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL