Documentation
¶
Overview ¶
Package index defines the Trickster Cache Index
Index ¶
- Constants
- Variables
- type IndexedClient
- func (idx *IndexedClient) Clear()
- func (idx *IndexedClient) Close() error
- func (idx *IndexedClient) Connect() error
- func (z *IndexedClient) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *IndexedClient) EncodeMsg(en *msgp.Writer) (err error)
- func (z *IndexedClient) MarshalMsg(b []byte) (o []byte, err error)
- func (z *IndexedClient) Msgsize() (s int)
- func (idx *IndexedClient) Remove(cacheKeys ...string) error
- func (idx *IndexedClient) Retrieve(cacheKey string) ([]byte, status.LookupStatus, error)
- func (idx *IndexedClient) RetrieveReference(cacheKey string) (any, status.LookupStatus, error)
- func (idx *IndexedClient) Store(cacheKey string, byteData []byte, ttl time.Duration) error
- func (idx *IndexedClient) StoreReference(cacheKey string, data cache.ReferenceObject, ttl time.Duration) error
- func (z *IndexedClient) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (idx *IndexedClient) UpdateOptions(o *options.Options)
- type IndexedClientOptions
- func (z *IndexedClientOptions) DecodeMsg(dc *msgp.Reader) (err error)
- func (z IndexedClientOptions) EncodeMsg(en *msgp.Writer) (err error)
- func (z IndexedClientOptions) MarshalMsg(b []byte) (o []byte, err error)
- func (z IndexedClientOptions) Msgsize() (s int)
- func (z *IndexedClientOptions) UnmarshalMsg(bts []byte) (o []byte, err error)
- type Object
- func (z *Object) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *Object) EncodeMsg(en *msgp.Writer) (err error)
- func (o *Object) Equal(other *Object) bool
- func (z *Object) MarshalMsg(b []byte) (o []byte, err error)
- func (z *Object) Msgsize() (s int)
- func (o *Object) ToBytes() ([]byte, error)
- func (z *Object) UnmarshalMsg(bts []byte) (o []byte, err error)
- type Objects
- type SyncObjects
- func (i *SyncObjects) DecodeMsg(dc *msgp.Reader) (err error)
- func (i *SyncObjects) Delete(key any)
- func (i *SyncObjects) EncodeMsg(en *msgp.Writer) (err error)
- func (i *SyncObjects) FromObjects(in Objects)
- func (i *SyncObjects) Keys() []string
- func (i *SyncObjects) MarshalMsg(b []byte) (o []byte, err error)
- func (i *SyncObjects) Msgsize() (s int)
- func (i *SyncObjects) Store(key, value any)
- func (i *SyncObjects) ToObjects() Objects
- func (i *SyncObjects) UnmarshalMsg(bts []byte) (o []byte, err error)
Constants ¶
const IndexKey = "cache.index"
IndexKey is the key under which the index will write itself to its associated cache
Variables ¶
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) 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 ¶
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 ¶
ObjectFromBytes returns a deserialized Cache Object from a serialized byte slice
func (*Object) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
func (*Object) Msgsize ¶
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
type Objects ¶
Objects are the set of objects in the Index by cacheKey, represented as a map for encoding and decoding purposes
func (Objects) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type SyncObjects ¶
SyncObjects is a cache of Index Objects, backed by a sync.Map, that supports msgp encoding and decoding
func (*SyncObjects) Delete ¶
func (i *SyncObjects) Delete(key any)
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)