cache

package
v0.0.0-...-eadad3b Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cache provides an in-memory cache for aggregate and process instances.

Index

Constants

View Source
const DefaultTTL = 1 * time.Hour

DefaultTTL is the default *minimum* period of time to keep cache records in memory after they were last used.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// TTL is the *minimum* period of time to keep cache records in memory after
	// they were last used. If it is non-positive, DefaultTTL is used.
	TTL time.Duration

	// Logger is the target for log messages about modifications to the cache.
	Logger logging.Logger
	// contains filtered or unexported fields
}

Cache is an in-memory cache for storing aggregate and process instances for a single handler.

func (*Cache) Acquire

func (c *Cache) Acquire(
	ctx context.Context,
	w handler.UnitOfWork,
	id string,
) (*Record, error)

Acquire locks and returns the cache record with the given ID, and ties its lifetime to w.

The lock on the record is automatically released when w is completed. The record is removed from the cache if w fails.

If the record has already been acquired, it blocks until the record is released or ctx is canceled.

func (*Cache) Discard

func (c *Cache) Discard(rec *Record)

Discard forcibly removes an acquired record from the cache.

func (*Cache) Run

func (c *Cache) Run(ctx context.Context) error

Run manages evicting idle records from the cache until ctx is canceled.

type Record

type Record struct {
	Instance interface{} // note: exposed, but still protected by m
	// contains filtered or unexported fields
}

Record is an entry in the cache.

Jump to

Keyboard shortcuts

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