cache

package
v4.0.0-alpha2 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package cache provides ready-to-use in-memory cache mechanisms

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultBigCacheConfig

func DefaultBigCacheConfig() bigcache.Config

Types

type EventWithContext

type EventWithContext struct {
	*tree.NodeChangeEvent
	Ctx context.Context
}

EventWithContext composes a NodeChangeEvent and a context

type EventsBatcher

type EventsBatcher struct {
	Events chan *EventWithContext
	Done   chan bool
	// contains filtered or unexported fields
}

EventsBatcher debounces events on a given timeframe and calls process on them afterward Use globalCtx.Done() to stop listening to events

func NewEventsBatcher

func NewEventsBatcher(ctx context.Context, debounce time.Duration, idle time.Duration, max int, atomic bool, process func(context.Context, ...*tree.NodeChangeEvent)) *EventsBatcher

NewEventsBatcher initializes a new EventsBatcher

func (*EventsBatcher) Start

func (b *EventsBatcher) Start()

Start starts listening to incoming events

type InstrumentedCache

type InstrumentedCache struct {
	bigcache.BigCache
	// contains filtered or unexported fields
}

InstrumentedCache wraps BigCache with metrics

func (*InstrumentedCache) Close

func (i *InstrumentedCache) Close() error

Close stops internal timer for reporting statistics

func (*InstrumentedCache) Delete

func (i *InstrumentedCache) Delete(key string) error

func (*InstrumentedCache) KeysByPrefix

func (i *InstrumentedCache) KeysByPrefix(prefix string) (res []string, e error)

func (*InstrumentedCache) Reset

func (i *InstrumentedCache) Reset() error

func (*InstrumentedCache) Set

func (i *InstrumentedCache) Set(key string, entry []byte) error

Set adds a key/value to the cache.

type KeyMutex

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

KeyMutex allows locking resource by a unique ID instead of using a global lock

func NewKeyMutex

func NewKeyMutex() *KeyMutex

NewKeyMutex creates a new KeyMutex.

func (*KeyMutex) Lock

func (km *KeyMutex) Lock(key string)

Lock locks the KeyMutex by unique ID.

func (*KeyMutex) Unlock

func (km *KeyMutex) Unlock(key string)

Unlock unlocks the KeyMutex by unique ID.

type Option

type Option func(o *Options)

func WithCleanWindow

func WithCleanWindow(t time.Duration) Option

func WithEviction

func WithEviction(t time.Duration) Option

type Options

type Options struct {
	EvictionTime time.Duration
	CleanWindow  time.Duration
}

type Sharded

type Sharded interface {
	Set(key string, entry []byte) error
	Get(key string) ([]byte, error)
	Delete(key string) error
	Reset() error
	KeysByPrefix(prefix string) ([]string, error)
	Close() error
}

func NewSharded

func NewSharded(identifier string, opts ...Option) Sharded

NewSharded creates a cache instance instrumented with a regular report of statistics

type Short

type Short interface {
	Get(key string) (value interface{}, ok bool)
	Set(key string, value interface{})
	SetWithExpiry(key string, value interface{}, duration time.Duration)
	Delete(k string)
	Reset() error
	KeysByPrefix(prefix string) ([]string, error)
	Iterate(it func(key string, val interface{}))
	Close() error
}

func NewShort

func NewShort(opts ...Option) Short

Jump to

Keyboard shortcuts

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