mem

package
v0.0.0-...-98ba599 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

package mem contains an implementation of the fes backend using an in-memory cache.

This implementation is typically used for development and test purposes. However, if you are targeting pure performance, you can use this backend to effectively trade in persistence-related guarantees (e.g. fault-tolerance) to avoid overhead introduced by other event stores, such as the NATS implementation.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEventLimitExceeded = &fes.EventStoreErr{
		S: "event limit exceeded",
	}
)

Functions

This section is empty.

Types

type Backend

type Backend struct {
	pubsub.Publisher
	Config
	// contains filtered or unexported fields
}

Backend is an in-memory, fes-compatible backend using a map for active entities with a LRU cache to store completed event streams, evicting oldest ones if it runs out of space. Active entities will never be deleted.

func NewBackend

func NewBackend(cfgs ...Config) *Backend

func (*Backend) Append

func (b *Backend) Append(event *fes.Event) error

func (*Backend) Get

func (b *Backend) Get(key fes.Aggregate) ([]*fes.Event, error)

func (*Backend) Len

func (b *Backend) Len() int

func (*Backend) List

func (b *Backend) List(matcher fes.AggregateMatcher) ([]fes.Aggregate, error)

Note: list does not return the cache contents

type Config

type Config struct {
	// MaxKeys specifies the limit of keys (or aggregates) in the backend.
	// If set to 0, MaxInt32 will be used as the limit.
	MaxKeys int

	// MaxEventsPerKey specifies a limit on the number
	MaxEventsPerKey int
}

Config contains the user-configurable options of the in-memory backend.

To limit the memory consumption of the backend, you can make use of the MaxKeys and MaxEventsPerKey. The absolute maximum memory usage is the product of the two limits.

Jump to

Keyboard shortcuts

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