Help us shape the future of Go! Take the 2026 Go Developer Survey

cache

package
v0.0.35 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Initialize cache instances
	Init(ctx context.Context) error
	// List cache instances
	List(ctx context.Context) []string
	// Create a new cache instance
	Create(ctx context.Context, cfg *CacheInstanceConfig) error
	// GetDetails returns a cache instance details
	GetDetails(ctx context.Context, name string) (*CacheInstanceConfig, error)
	// Delete a cache instance or a candidate in a cache instance.
	// the name should be in the format $cache/$candidate to delete a candidate
	Delete(ctx context.Context, name string) error
	// Exists return true if a cache instance called 'name' exists,
	// false otherwise
	Exists(ctx context.Context, name string) bool
	// Clone a cache instance
	Clone(ctx context.Context, name, cname string) (string, error)
	// Create a candidate for an existing cache instance
	CreateCandidate(ctx context.Context, name, candidate, owner string, priority int32) (string, error)
	// GetCandidate returns the candidate details; owner and priority
	GetCandidate(ctx context.Context, name, cname string) (*CandidateDetails, error)
	// Candidates returns the list of candidates created for a cache instance
	Candidates(ctx context.Context, name string) ([]*CandidateDetails, error)

	// WriteValue writes a bytes value into the named cache
	WriteValue(ctx context.Context, name string, wo *Opts, vb []byte) error
	// CreatePruneID creates a pruneID that can be used to trigger a prune
	// with ApplyPrune once all updates are pushed
	CreatePruneID(ctx context.Context, name string, force bool) (string, error)
	// ApplyPrune runs a prune on the config and state stores of the cache instance.
	// It deletes all values that where not updated since the pruneID was generated.
	ApplyPrune(ctx context.Context, name, id string) error

	// ReadValue reads a value from a cache instance.
	ReadValue(ctx context.Context, name string, ro *Opts) (chan *Entry, error)
	// ReadValuePeriodic reads a value from a cache instance every period
	ReadValuePeriodic(ctx context.Context, name string, ro *Opts, period time.Duration) (chan *Entry, error)
	// DeleteValue deletes a value from a cache instance.
	DeleteValue(ctx context.Context, name string, wo *Opts) error
	// DeletePrefix deletes any key/value with the given prefix
	DeletePrefix(ctx context.Context, name string, wo *Opts) error
	// Diff returns the changes made to a candidate
	Diff(ctx context.Context, name, candidate string) ([][]string, []*Entry, error)
	// Discard drops the changes made to a candidate
	Discard(ctx context.Context, name, candidate string) error
	// Close the underlying resources, like the persistent store
	Close() error
	// Commit candidate into the intended store
	Commit(ctx context.Context, name, candidate string) error

	// ReadKeys Read all the keys of the given store
	ReadKeys(ctx context.Context, name string, store Store) (chan *Entry, error)

	Clear(ctx context.Context, name string) error
	NumInstances() int
	Watch(ctx context.Context, name string, store Store, prefixes [][]string) (chan *Entry, error)
}

func New

func New(cfg *config.CacheConfig) Cache

type CacheInstanceConfig

type CacheInstanceConfig struct {
	Name            string
	StoreType       string
	Dir             string
	PruneIDLifetime time.Duration
}

type CandidateDetails

type CandidateDetails struct {
	CacheName     string
	CandidateName string
	Owner         string
	Priority      int32
}

type Entry

type Entry struct {
	Timestamp uint64
	Owner     string
	Priority  int32
	P         []string
	V         []byte
}

func (*Entry) String

func (e *Entry) String() string

type InstanceStats

type InstanceStats struct {
	Name     string
	KeyCount map[string]int64
}

type Opts

type Opts struct {
	Store         Store
	Path          [][]string // TODO: replace with cachepb.Path
	Owner         string
	Priority      int32
	PriorityCount uint64
	KeysOnly      bool // used with the intents store only
}

type StatsResponse

type StatsResponse struct {
	NumInstances  int
	InstanceStats map[string]*InstanceStats
}

type Store

type Store int8
const (
	StoreConfig   Store = 0
	StoreState    Store = 1
	StoreIntended Store = 2
	StoreIntents  Store = 3
)

Jump to

Keyboard shortcuts

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