index

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: Apache-2.0 Imports: 9 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

This section is empty.

Functions

This section is empty.

Types

type Index

type Index struct {
	// 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 map[string]*Object `msg:"objects"`
	// contains filtered or unexported fields
}

Index maintains metadata about a Cache when Retention enforcement is managed internally, like memory or bbolt. It is not used for independently managed caches like Redis.

func NewIndex

func NewIndex(cacheName, cacheType string, indexData []byte, cfg config.CacheIndexConfig, bulkRemoveFunc func([]string), flushFunc func(cacheKey string, data []byte)) *Index

NewIndex returns a new Index based on the provided inputs

func (*Index) DecodeMsg

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

DecodeMsg implements msgp.Decodable

func (*Index) EncodeMsg

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

EncodeMsg implements msgp.Encodable

func (*Index) GetExpiration

func (idx *Index) GetExpiration(cacheKey string) time.Time

GetExpiration returns the cache index's expiration for the object of the given key

func (*Index) MarshalMsg

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

MarshalMsg implements msgp.Marshaler

func (*Index) Msgsize

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

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

func (*Index) RemoveObject

func (idx *Index) RemoveObject(key string)

RemoveObject removes an Object's Metadata from the Index

func (*Index) RemoveObjects added in v1.0.3

func (idx *Index) RemoveObjects(keys []string, noLock bool)

RemoveObjects removes a list of Objects' Metadata from the Index

func (*Index) ToBytes

func (idx *Index) ToBytes() []byte

ToBytes returns a serialized byte slice representing the Index

func (*Index) UnmarshalMsg

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

UnmarshalMsg implements msgp.Unmarshaler

func (*Index) UpdateObject

func (idx *Index) UpdateObject(obj *Object)

UpdateObject writes or updates the Index Metadata for the provided Object

func (*Index) UpdateObjectAccessTime

func (idx *Index) UpdateObjectAccessTime(key string)

UpdateObjectAccessTime updates the LastAccess for the object with the provided key

func (*Index) UpdateObjectTTL

func (idx *Index) UpdateObjectTTL(key string, ttl time.Duration)

UpdateObjectTTL updates the Expiration for the object with the provided key

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 time.Time `msg:"expiration"`
	// LastWrite is the time the object was last Written
	LastWrite time.Time `msg:"lastwrite"`
	// LastAccess is the time the object was last Accessed
	LastAccess time.Time `msg:"lastaccess"`
	// 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 seralized 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) 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

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

Jump to

Keyboard shortcuts

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