fullrelationcache

package
v1.57.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package fullrelationcache caches the complete set of relationships for one objecttype:objectid#relation at one revision, and serves relationship queries from that set. A set never serves a query at a different revision.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewProxy

func NewProxy(delegate datastore.Datastore, sets cache.Cache[SetKey, *CachedSet],
	counter AccessCounter, opts Options,
) datastore.Datastore

NewProxy returns a datastore that serves snapshot queries for a hot object#relation from complete sets. The caller owns sets and counter.

Types

type AccessCounter

type AccessCounter interface {
	// Touch records one access to key and returns its count.
	Touch(key string) uint64

	// Close releases the counter storage.
	Close()
}

AccessCounter counts accesses per set key. The proxy uses the count to decide when an object#relation is hot enough to materialize.

A count is exact for its key while its counter lives. Set keys include the revision, so a count is the number of reads at one revision. A counter expires when no Touch occurs for the window. If the cache evicts a counter or refuses to admit it, the next Touch restarts the count at 1. A restarted count can only delay a materialization. It can never make a served answer wrong.

func NewAccessCounter

func NewAccessCounter(maxCost int64, window time.Duration) (AccessCounter, error)

NewAccessCounter returns an AccessCounter that keeps one counter per key in a pkg/cache cache of maxCost bytes. A counter expires when no Touch occurs for window.

type CachedSet

type CachedSet struct {
	// Complete is true if Rels holds every relationship of the object#relation at the revision of the key.
	Complete bool

	// Rels holds the relationships of a complete set. It is nil for a too-big memo.
	Rels []tuple.Relationship

	// MemoizedAt is the creation time of a too-big memo. It is zero for a complete set.
	MemoizedAt time.Time
}

CachedSet is the value for a SetKey or a too-big memo key. A memo has Complete=false. It sends its object#relation to the datastore at every revision until the memo is older than tooBigMemoReprobeInterval or the cache evicts it.

func (*CachedSet) Cost

func (s *CachedSet) Cost() int64

Cost returns the approximate size of the set in bytes.

type Options

type Options struct {
	// MaterializeThreshold is the access count at one revision that materializes an object#relation at that revision.
	MaterializeThreshold uint64

	// MaximumSetSize is the largest set that the proxy stores. A larger set gets a too-big memo.
	MaximumSetSize uint64

	// NowFunc gives the time for serve-time expiration and too-big memo age. nil means time.Now.
	NowFunc func() time.Time
}

Options configures the full relation cache proxy.

type SetKey

type SetKey string

SetKey identifies one object#relation at one revision.

func NewSetKey

func NewSetKey(resourceType, objectID, relation, revision string) SetKey

NewSetKey returns the SetKey for an object#relation at a revision.

func NewTooBigMemoKey

func NewTooBigMemoKey(resourceType, objectID, relation string) SetKey

NewTooBigMemoKey returns the revision-independent key for a too-big memo. A valid type name or object ID cannot start with "!" or contain "::". Thus a memo key never parses as a relationship and never equals a set key.

func (SetKey) KeyString

func (k SetKey) KeyString() string

KeyString implements the cache key interface.

Jump to

Keyboard shortcuts

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