inmem

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2022 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package inmem implements a layer of services in memory using purely Go constructs. In theory, they can be swapped out for services implemented using other tech, e.g. databases, redis, etc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCache added in v0.0.11

func NewCache(config CacheConfig) (*bigcache.BigCache, error)

Types

type CacheConfig added in v0.0.11

type CacheConfig struct {
	// Total capacity of cache in MB.
	Size int
	// Time-to-live for each cache entry before automatic deletion.
	TTL time.Duration
}

type ChunkProxy added in v0.0.11

type ChunkProxy struct {
	otf.Application
	logr.Logger
	// contains filtered or unexported fields
}

ChunkProxy is a caching proxy for log chunks, proxying requests to the backend.

func NewChunkProxy added in v0.0.11

func NewChunkProxy(app otf.Application, logger logr.Logger, cache otf.Cache, backend otf.ChunkStore) (*ChunkProxy, error)

func (*ChunkProxy) GetChunk added in v0.0.11

func (c *ChunkProxy) GetChunk(ctx context.Context, opts otf.GetChunkOptions) (otf.Chunk, error)

GetChunk attempts to retrieve a chunk from the cache before falling back to using the backend store.

func (*ChunkProxy) GetChunkByID added in v0.0.12

func (c *ChunkProxy) GetChunkByID(ctx context.Context, chunkID int) (otf.PersistedChunk, error)

func (*ChunkProxy) PutChunk added in v0.0.11

func (c *ChunkProxy) PutChunk(ctx context.Context, chunk otf.Chunk) (otf.PersistedChunk, error)

PutChunk writes a chunk of data to the backend store before caching it.

func (*ChunkProxy) Start added in v0.0.12

func (c *ChunkProxy) Start(ctx context.Context) error

Start the chunk proxy daemon, which keeps the cache up-to-date.

type Mapper added in v0.0.12

type Mapper struct {
	otf.Application
	// contains filtered or unexported fields
}

Mapper is an in-memory implementation of a mapper.

A mapper maintains mappings between various resource identifiers, which are used by upstream layers to make decisions and efficiently lookup resources.

For instance, the authorization layer needs to decide whether to permit access and cannot do so based on a single identifier (e.g. a run id) but needs to know which organization and workspace id it relates to.

Whereas the persistence layer, with access to mappings, need only lookup resources based on the most appropriate identifier for which it maintains an index, rather having to support lookups using a multitude of identifiers.

func NewMapper added in v0.0.12

func NewMapper(app otf.Application) *Mapper

NewMapper constructs the mapper

func (*Mapper) LookupWorkspaceID added in v0.0.12

func (m *Mapper) LookupWorkspaceID(spec otf.WorkspaceSpec) string

LookupWorkspaceID looks up the ID corresponding to the given spec. If the spec already contains an ID then that is returned, otherwise the mapper looks up the ID corresponding to the given organization and workspace name. If the spec is invalid, then an empty string is returned.

func (*Mapper) Populate added in v0.0.12

func (m *Mapper) Populate(ctx context.Context, ws otf.WorkspaceService, rs otf.RunService) error

Populate populates the mapper with identifiers

func (*Mapper) Start added in v0.0.12

func (m *Mapper) Start(ctx context.Context) error

Start the mapper, populate entries from the DB, and watch changes, updating mappings accordingly.

type PubSub added in v0.0.12

type PubSub struct {
	// contains filtered or unexported fields
}

PubSub implements a 'pub-sub' service using go channels.

func NewPubSub added in v0.0.12

func NewPubSub() *PubSub

func (*PubSub) Publish added in v0.0.12

func (e *PubSub) Publish(event otf.Event)

Publish relays an event to a list of subscribers

func (*PubSub) Subscribe added in v0.0.12

func (e *PubSub) Subscribe(ctx context.Context, name string) (<-chan otf.Event, error)

Subscribe subscribes the caller to a stream of events.

Jump to

Keyboard shortcuts

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