persist

package
v3.6.7+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2021 License: Apache-2.0 Imports: 11 Imported by: 18

Documentation

Index

Constants

View Source
const (
	// DefaultTTL specifies the "Time To Live" of the disk storage.
	DefaultTTL = 1 * time.Minute
)

Variables

View Source
var (
	// ErrNotFound defines an error that will be returned when trying to access a storage entry that can't be found
	ErrNotFound = errors.New("key not found")
)

Functions

func DefaultPath

func DefaultPath(integrationName string) string

DefaultPath returns a default folder/filename dir to a Storer for an integration from the given name. The name of the file will be the name of the integration with the .json extension.

func SetNow

func SetNow(newNow func() time.Time)

SetNow forces a different "current time" for the Storer. Deprecated: This function is useful only for unit testing outside the persist package.

Types

type StorePath

type StorePath interface {
	GetFilePath() string
	CleanOldFiles()
}

StorePath will handle the location for the persistence.

func NewStorePath

func NewStorePath(integrationName, integrationID string, ilog log.Logger, ttl time.Duration) (StorePath, error)

NewStorePath create a new instance of StorePath

type Storer

type Storer interface {
	// Set associates a value with a given key. Implementors must save also the time when it has been stored and return it.
	// The value can be any type.
	Set(key string, value interface{}) int64
	// Get gets the value associated to a given key and stores in the value referenced by the pointer passed as argument.
	// It returns the Unix timestamp when the value was stored (in seconds), or an error if the Get operation failed.
	// It may return any type of value.
	Get(key string, valuePtr interface{}) (int64, error)
	// Delete removes the cached data for the given key. If the data does not exist, the system does not return
	// any error.
	Delete(key string) error
	// Save persists all the data in the storer.
	Save() error
}

Storer defines the interface of a Key-Value storage system, which is able to store the timestamp where the key was stored.

func NewFileStore

func NewFileStore(storagePath string, ilog log.Logger, ttl time.Duration) (Storer, error)

NewFileStore returns a disk-backed Storer using the provided file dir

func NewInMemoryStore

func NewInMemoryStore() Storer

NewInMemoryStore will create and initialize an in-memory Storer (not persistent).

Jump to

Keyboard shortcuts

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