contrib

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NowFunc

type NowFunc func() time.Time

type OtterCache

type OtterCache struct {

	// Now is the Now() function the cache will use to determine
	// the current time which is used to calculate expired values
	// Defaults to time.Now()
	Now NowFunc
	// contains filtered or unexported fields
}

OtterCache is an alternative cache implementation which uses a high performance lockless cache suitable for use in high concurrency environments where mutex contention is an issue.

func NewOtterCache

func NewOtterCache(maxBytes int64) (*OtterCache, error)

NewOtterCache instantiates a new cache instance

func (*OtterCache) Add

func (o *OtterCache) Add(key string, value transport.ByteView)

Add adds the item to the cache. However, otter has the side effect of rejecting an item if the items size (aka, cost) is larger than the capacity (max cost) of the cache divided by 10.

If Stats() reports a high number of Rejected items due to large cached items exceeding the maximum cost of the "Hot Cache", then you should increase the size of the cache such that no cache item is larger than the total size of the cache divided by 10.

See s3fifo/policy.go NewPolicy() for details

func (*OtterCache) Bytes

func (o *OtterCache) Bytes() int64

Bytes always returns 0 bytes used. Otter does not keep track of total bytes, and it is impractical for us to attempt to keep track of total bytes in the cache. Tracking the size of Add and Eviction is easy. However, we must also adjust the total bytes count when items with the same key are replaced. Doing so is more computationally expensive as we must check the cache for an existing item, subtract the existing byte count, then add the new byte count of the replacing item.

Arguably reporting the total bytes used is not as useful as hit ratio in a production environment.

func (*OtterCache) Close

func (o *OtterCache) Close()

func (*OtterCache) Get

func (o *OtterCache) Get(key string) (transport.ByteView, bool)

Get returns the item from the cache

func (*OtterCache) Remove

func (o *OtterCache) Remove(key string)

func (*OtterCache) Stats

func (o *OtterCache) Stats() groupcache.CacheStats

Jump to

Keyboard shortcuts

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