Documentation
¶
Index ¶
- Constants
- Variables
- func SaveToFile(c Cache, path string) error
- type Cache
- func Deserialize(r io.Reader, slotSize, slotCount int32) (Cache, error)
- func DeserializeEx(r io.Reader, slotSize, mCap, sCap int32) (Cache, error)
- func DeserializeExV100(d *gob.Decoder, slotSize, mCap, sCap int32) (Cache, error)
- func DeserializeExV101(d *gob.Decoder, slotSize, mCap, sCap int32) (Cache, error)
- func LoadFromFile(path string, slotSize, slotCount int32) (Cache, error)
- func LoadFromFileEx(path string, slotSize, mCap, sCap int32) (Cache, error)
- func New(slotSize, slotCap int32) Cache
- func NewEx(slotSize, mCap, sCap int32) Cache
- type InternalStatsCache
- type TrackerCache
- func (s *TrackerCache) Capacity() uint64
- func (s *TrackerCache) Clear()
- func (s *TrackerCache) Close() error
- func (s *TrackerCache) Entries() uint64
- func (s *TrackerCache) Get(key string, buf []byte) []byte
- func (s *TrackerCache) Has(key string) bool
- func (s *TrackerCache) Hits() uint64
- func (s *TrackerCache) Misses() uint64
- func (s *TrackerCache) Serialize(w io.Writer) error
- func (s *TrackerCache) Set(key string, val []byte) error
- func (s *TrackerCache) Sets() uint64
- func (s *TrackerCache) Size() uint64
- func (s *TrackerCache) Window(name string) (uint64, bool)
- type TrackerWindow
Constants ¶
const (
DefaultSmallQueuePercent = 10
)
Variables ¶
var ErrAlreadyExists = errors.New("otto: key already exists in cache")
var ErrClosedCache = errors.New("otto: can't perform operation on closed cache")
var ErrEmptyValue = errors.New("otto: can't add empty value to cache")
var ErrTooBig = errors.New("otto: value is too big for cache")
Functions ¶
func SaveToFile ¶ added in v0.0.11
SaveToFile serializes the cache as a file in the provided path.
Types ¶
type Cache ¶
type Cache interface {
// Set inserts an item in the cache. If the cache is full an element
// will be evicted.
//
// NOTE: updates are not supported.
Set(key string, val []byte) error
// Get retrieves - if available - an item from the cache. If the item
// does not exist it will return nil.
Get(key string, buf []byte) []byte
// Has checks if an item - identified by its key - is present in the
// cache.
Has(key string) bool
// Clear clears the cache, removing every entry without freeing the memory.
Clear()
// Close clears the cache, removing every entry and freeing the memory.
Close() error
// Entries returns the number of entries currently stored in the cache.
Entries() uint64
// Size returns the sum of the sizes of all the entries currently
// stored in the cache.
Size() uint64
// Capacity returns the theoretical capacity of the cache.
Capacity() uint64
// Serialize write the cache to a writer. The cache can then be
// reinstantiated using the otto.Deserialize function.
Serialize(w io.Writer) error
}
func Deserialize ¶
Deserialize deserializes the cache from a byte stream. Refer to the New method for the usage of slotSize & slotCount arguments.
func DeserializeEx ¶ added in v0.0.27
DeserializeEx deserializes the cache from a byte stream. Refer to the NewEx method for the usage of slotSize & mCap & sCap arguments.
func DeserializeExV100 ¶ added in v0.0.63
Deserializer for version otto-cache-1.0.0
func DeserializeExV101 ¶ added in v0.0.63
Deserializer for version otto-cache-1.0.1
func LoadFromFile ¶
LoadFromFile deserializes the cache from the file at the provided path. Refer to the New method for the usage of slotSize & slotCount arguments.
func LoadFromFileEx ¶ added in v0.0.27
LoadFromFileEx deserializes the cache from the file at the provided path. Refer to the NewEx method for the usage of slotSize & mCap & sCap arguments.
func New ¶
New creates a new otto.Cache with a fixed size of slotSize * slotCount. Calling the Set method on a full cache will cause elements to be evicted according to the S3-FIFO algorithm.
func NewEx ¶ added in v0.0.16
NewEx creates a new otto.Cache with a fixed size of slotSize * (mCap + sCap). Calling the Set method on a full cache will cause elements to be evicted according to the S3-FIFO algorithm.
mCapacity and sCapacity configure the size of the m and the s queue respectively. To learn more about S3-FIFO visit https://s3fifo.com/
type InternalStatsCache ¶ added in v0.0.36
type InternalStatsCache interface {
Cache
// MQueueEntries returns the number of entries in the M-queue.
MQueueEntries() uint64
// MQueueCapacity returns the capacity of the M-queue.
MQueueCapacity() uint64
// SQueueEntries returns the number of entries in the S-queue.
SQueueEntries() uint64
// SQueueCapacity returns the capacity of the S-queue.
SQueueCapacity() uint64
}
type TrackerCache ¶ added in v0.0.11
type TrackerCache struct {
// contains filtered or unexported fields
}
func NewTracker ¶ added in v0.0.11
func NewTracker(c Cache, windows map[string]TrackerWindow) *TrackerCache
func (*TrackerCache) Capacity ¶ added in v0.0.32
func (s *TrackerCache) Capacity() uint64
func (*TrackerCache) Clear ¶ added in v0.0.11
func (s *TrackerCache) Clear()
func (*TrackerCache) Close ¶ added in v0.0.11
func (s *TrackerCache) Close() error
func (*TrackerCache) Entries ¶ added in v0.0.11
func (s *TrackerCache) Entries() uint64
func (*TrackerCache) Get ¶ added in v0.0.11
func (s *TrackerCache) Get(key string, buf []byte) []byte
func (*TrackerCache) Has ¶ added in v0.0.56
func (s *TrackerCache) Has(key string) bool
func (*TrackerCache) Hits ¶ added in v0.0.11
func (s *TrackerCache) Hits() uint64
func (*TrackerCache) Misses ¶ added in v0.0.11
func (s *TrackerCache) Misses() uint64
func (*TrackerCache) Serialize ¶ added in v0.0.11
func (s *TrackerCache) Serialize(w io.Writer) error
func (*TrackerCache) Set ¶ added in v0.0.11
func (s *TrackerCache) Set(key string, val []byte) error
func (*TrackerCache) Sets ¶ added in v0.0.11
func (s *TrackerCache) Sets() uint64
func (*TrackerCache) Size ¶ added in v0.0.32
func (s *TrackerCache) Size() uint64