index

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package index defines the Trickster Cache Index

Index

Constants

View Source
const IndexKey = "cache.index"

IndexKey is the key under which the index will write itself to its associated cache

Variables

View Source
var (
	ErrIndexInvalidCacheKey = errors.New("cannot store index")
	ErrInvalidCacheBackend  = errors.New("invalid cache backend for reference access")
)

Functions

This section is empty.

Types

type IndexedClient

type IndexedClient struct {
	// Client is the underlying cache client used by the Index
	Client cache.Client `msg:"-"`
	// CacheSize represents the size of the cache in bytes
	CacheSize int64 `msg:"cache_size"`
	// ObjectCount represents the count of objects in the Cache
	ObjectCount int64 `msg:"object_count"`
	// Objects is a map of Objects in the Cache
	Objects SyncObjects `msg:"objects"`
	// Time the index was last flushed
	LastFlush atomicx.Time `msg:"LastFlush,extension"`
	// contains filtered or unexported fields
}

The IndexedClient maintains metadata about a cache.Client when Retention enforcement is managed internally, like memory or bbolt. It is not used for independently managed caches like Redis.

func NewIndexedClient

func NewIndexedClient(
	cacheName, cacheProvider string,
	o *options.Options,
	client cache.Client,
	opts ...func(*IndexedClientOptions),
) *IndexedClient

func (*IndexedClient) Clear

func (idx *IndexedClient) Clear()

Clear the index from its currently tracked cache objects

func (*IndexedClient) Close

func (idx *IndexedClient) Close() error

Stop the indexed cache, flush its state, and close the underlying cache

func (*IndexedClient) Connect

func (idx *IndexedClient) Connect() error

No-op -- implements the cache.Client interface

func (*IndexedClient) DecodeMsg

func (z *IndexedClient) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*IndexedClient) EncodeMsg

func (z *IndexedClient) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*IndexedClient) MarshalMsg

func (z *IndexedClient) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*IndexedClient) Msgsize

func (z *IndexedClient) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*IndexedClient) Remove

func (idx *IndexedClient) Remove(cacheKeys ...string) error

Remove implements the cache.Client interface and removes the object from the cache and index

func (*IndexedClient) Retrieve

func (idx *IndexedClient) Retrieve(cacheKey string) ([]byte, status.LookupStatus, error)

Retrieve implements the cache.Client interface, looking up the object and updating the index last access time

func (*IndexedClient) RetrieveReference

func (idx *IndexedClient) RetrieveReference(cacheKey string) (any, status.LookupStatus, error)

func (*IndexedClient) Store

func (idx *IndexedClient) Store(cacheKey string, byteData []byte, ttl time.Duration) error

func (*IndexedClient) StoreReference

func (idx *IndexedClient) StoreReference(cacheKey string, data cache.ReferenceObject, ttl time.Duration) error

func (*IndexedClient) UnmarshalMsg

func (z *IndexedClient) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*IndexedClient) UpdateOptions

func (idx *IndexedClient) UpdateOptions(o *options.Options)

UpdateOptions updates the existing IndexedClient with a new Options reference

type IndexedClientOptions

type IndexedClientOptions struct {
	NeedsFlushInterval bool
	NeedsReapInterval  bool
}

IndexedClientOptions modify an IndexedClient's behavior.

func (*IndexedClientOptions) DecodeMsg

func (z *IndexedClientOptions) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (IndexedClientOptions) EncodeMsg

func (z IndexedClientOptions) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (IndexedClientOptions) MarshalMsg

func (z IndexedClientOptions) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (IndexedClientOptions) Msgsize

func (z IndexedClientOptions) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*IndexedClientOptions) UnmarshalMsg

func (z *IndexedClientOptions) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Object

type Object struct {
	// Key represents the name of the Object and is the
	// accessor in a hashed collection of Cache Objects
	Key string `msg:"key"`
	// Expiration represents the time that the Object expires from Cache
	Expiration atomicx.Time `msg:"expiration,extension"`
	// LastWrite is the time the object was last Written
	LastWrite atomicx.Time `msg:"lastwrite,extension"`
	// LastAccess is the time the object was last Accessed
	LastAccess atomicx.Time `msg:"lastaccess,extension"`
	// Size the size of the Object in bytes
	Size int64 `msg:"size"`
	// Value is the value of the Object stored in the Cache
	// It is used by Caches but not by the Index
	Value []byte `msg:"value,omitempty"`
	// DirectValue is an interface value for storing objects by reference to a memory cache
	// Since we'd never recover a memory cache index from memory on startup, no need to msgpk
	ReferenceValue cache.ReferenceObject `msg:"-"`
}

Object contains metadata about an item in the Cache

func ObjectFromBytes

func ObjectFromBytes(data []byte) (*Object, error)

ObjectFromBytes returns a deserialized Cache Object from a serialized byte slice

func (*Object) DecodeMsg

func (z *Object) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Object) EncodeMsg

func (z *Object) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Object) Equal

func (o *Object) Equal(other *Object) bool

func (*Object) MarshalMsg

func (z *Object) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Object) Msgsize

func (z *Object) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Object) ToBytes

func (o *Object) ToBytes() ([]byte, error)

ToBytes returns a serialized byte slice representing the Object

func (*Object) UnmarshalMsg

func (z *Object) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Objects

type Objects map[string]*Object

Objects are the set of objects in the Index by cacheKey, represented as a map for encoding and decoding purposes

func (*Objects) DecodeMsg

func (z *Objects) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (Objects) EncodeMsg

func (z Objects) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (Objects) MarshalMsg

func (z Objects) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (Objects) Msgsize

func (z Objects) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Objects) UnmarshalMsg

func (z *Objects) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type SyncObjects

type SyncObjects struct {
	sync.Map
	// contains filtered or unexported fields
}

SyncObjects is a cache of Index Objects, backed by a sync.Map, that supports msgp encoding and decoding

func (*SyncObjects) DecodeMsg

func (i *SyncObjects) DecodeMsg(dc *msgp.Reader) (err error)

func (*SyncObjects) Delete

func (i *SyncObjects) Delete(key any)

func (*SyncObjects) EncodeMsg

func (i *SyncObjects) EncodeMsg(en *msgp.Writer) (err error)

func (*SyncObjects) FromObjects

func (i *SyncObjects) FromObjects(in Objects)

func (*SyncObjects) Keys

func (i *SyncObjects) Keys() []string

func (*SyncObjects) MarshalMsg

func (i *SyncObjects) MarshalMsg(b []byte) (o []byte, err error)

func (*SyncObjects) Msgsize

func (i *SyncObjects) Msgsize() (s int)

func (*SyncObjects) Store

func (i *SyncObjects) Store(key, value any)

func (*SyncObjects) ToObjects

func (i *SyncObjects) ToObjects() Objects

func (*SyncObjects) UnmarshalMsg

func (i *SyncObjects) UnmarshalMsg(bts []byte) (o []byte, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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