keycache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is a single-tenant keycache it is sharded for 2 reasons: * more granular GC (eg. less latency perceived by caller) * mild space savings cause keys are 1 byte shorter We shard on the first byte of the metric key, which we assume is evenly distributed.

func NewCache

func NewCache() *Cache

NewCache creates a new cache

func (*Cache) Clear

func (c *Cache) Clear(i int) int

Clear resets the given shard

func (*Cache) Len

func (c *Cache) Len() int

Len returns the length of the cache

func (*Cache) Touch

func (c *Cache) Touch(key schema.Key) bool

Touch marks the key as seen and returns whether it was seen before

type KeyCache

type KeyCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

KeyCache tracks for all orgs, which keys have been seen, and when was the last time

func NewKeyCache

func NewKeyCache(clearInterval time.Duration) *KeyCache

NewKeyCache creates a new KeyCache each clearInterval, all shards will be wiped (one at a time, spread out over the interval)

func (*KeyCache) Len

func (k *KeyCache) Len() int

Len returns the size across all orgs

func (*KeyCache) Touch

func (k *KeyCache) Touch(key schema.MKey) bool

Touch marks the key as seen and returns whether it was seen before callers should assure that t >= ref and t-ref <= 42 hours

type Shard

type Shard struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Shard tracks which SubKey's have been seen since the last prune

func NewShard

func NewShard() Shard

NewShard creates a new shard

func (*Shard) Len

func (s *Shard) Len() int

Len returns the length of the shard

func (*Shard) Reset

func (s *Shard) Reset()

Reset resets the shard, making it empty

func (*Shard) Touch

func (s *Shard) Touch(key schema.Key) bool

Touch marks the key as seen and returns whether it was seen before

type SubKey

type SubKey [15]byte

SubKey is the last 15 bytes of a 16 byte Key We can track Key-identified metrics with a SubKey because we shard by the first byte of the Key.

Jump to

Keyboard shortcuts

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