memory

package
v4.0.10+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package memory implements backend interface using a combination of Minheap (to store expiring items) and B-Tree for storing sorted dictionary of items. This package is used for caching layer

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Context is a context for opening the
	// database
	Context context.Context
	// BTreeDegree is a degree of B-Tree, 2 for example, will create a
	// 2-3-4 tree (each node contains 1-3 items and 2-4 children).
	BTreeDegree int
	// Clock is a clock for time-related operations
	Clock clockwork.Clock
	// Component is a logging component
	Component string
	// EventsOff turns off events generation
	EventsOff bool
	// BufferSize sets up event buffer size
	BufferSize int
	// Mirror mode is used when the memory backend is used for caching. In mirror
	// mode, record IDs for Put and PutRange requests are re-used (instead of
	// generating fresh ones) and expiration is turned off.
	Mirror bool
}

Config holds configuration for the backend

func (*Config) CheckAndSetDefaults

func (cfg *Config) CheckAndSetDefaults() error

CheckAndSetDefaults checks and sets default values

type Memory

type Memory struct {
	*sync.Mutex
	*log.Entry
	Config
	// contains filtered or unexported fields
}

Memory is a memory B-Tree based backend

func New

func New(cfg Config) (*Memory, error)

New creates a new memory backend

func (*Memory) Clock

func (m *Memory) Clock() clockwork.Clock

Clock returns clock used by this backend

func (*Memory) Close

func (m *Memory) Close() error

Close closes memory backend

func (*Memory) CloseWatchers

func (m *Memory) CloseWatchers()

CloseWatchers closes all the watchers without closing the backend

func (*Memory) CompareAndSwap

func (m *Memory) CompareAndSwap(ctx context.Context, expected backend.Item, replaceWith backend.Item) (*backend.Lease, error)

CompareAndSwap compares item with existing item and replaces it with replaceWith item

func (*Memory) Create

func (m *Memory) Create(ctx context.Context, i backend.Item) (*backend.Lease, error)

Create creates item if it does not exist

func (*Memory) Delete

func (m *Memory) Delete(ctx context.Context, key []byte) error

Delete deletes item by key, returns NotFound error if item does not exist

func (*Memory) DeleteRange

func (m *Memory) DeleteRange(ctx context.Context, startKey, endKey []byte) error

DeleteRange deletes range of items with keys between startKey and endKey Note that elements deleted by range do not produce any events

func (*Memory) Get

func (m *Memory) Get(ctx context.Context, key []byte) (*backend.Item, error)

Get returns a single item or not found error

func (*Memory) GetRange

func (m *Memory) GetRange(ctx context.Context, startKey []byte, endKey []byte, limit int) (*backend.GetResult, error)

GetRange returns query range

func (*Memory) KeepAlive

func (m *Memory) KeepAlive(ctx context.Context, lease backend.Lease, expires time.Time) error

KeepAlive updates TTL on the lease

func (*Memory) NewWatcher

func (m *Memory) NewWatcher(ctx context.Context, watch backend.Watch) (backend.Watcher, error)

NewWatcher returns a new event watcher

func (*Memory) Put

func (m *Memory) Put(ctx context.Context, i backend.Item) (*backend.Lease, error)

Put puts value into backend (creates if it does not exists, updates it otherwise)

func (*Memory) PutRange

func (m *Memory) PutRange(ctx context.Context, items []backend.Item) error

PutRange puts range of items into backend (creates if items does not exists, updates it otherwise)

func (*Memory) Update

func (m *Memory) Update(ctx context.Context, i backend.Item) (*backend.Lease, error)

Update updates item if it exists, or returns NotFound error

Jump to

Keyboard shortcuts

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