storages

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPartitionNum  uint64 = 16
	DefaultPartitionMask uint64 = 0xF
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

func (*Buffer) Bytes

func (o *Buffer) Bytes() []byte

func (*Buffer) Copy

func (o *Buffer) Copy(data []byte)

func (*Buffer) Free

func (o *Buffer) Free()

func (*Buffer) Reset

func (o *Buffer) Reset()

type DataDictionary

type DataDictionary interface {
	Add(key uint64, data []byte, expiration time.Time) error
	Get(key uint64) (Buffer, error)
	Clean(ctx context.Context) error
}

func NewMapDictionary

func NewMapDictionary(pool DataPool) DataDictionary

func NewPartitionedDictionary

func NewPartitionedDictionary(
	partitionNum uint64,
	partitionMask uint64,
	partitionFabric func() (DataDictionary, error),
) (DataDictionary, error)

func NewSyncMapDictionary

func NewSyncMapDictionary(pool DataPool) DataDictionary

type DataPool

type DataPool interface {
	Copy(data []byte, expiration time.Time) (Buffer, error)
	Clean(ctx context.Context) error
}

func NewDataPool

func NewDataPool(memPool MemoryPool) (DataPool, error)

type Error

type Error string
const (
	ErrOutOfLimit  Error = "out_of_the_limit"
	ErrKeyNotFound Error = "key_not_found"
	ErrKeyExpired  Error = "key_expired"
)

func (Error) Error

func (o Error) Error() string

type InMemStorages

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

func (*InMemStorages) Add

func (o *InMemStorages) Add(key, body []byte) error

func (*InMemStorages) Clean

func (o *InMemStorages) Clean(ctx context.Context) error

func (*InMemStorages) Get

func (o *InMemStorages) Get(key []byte) (Buffer, error)

func (*InMemStorages) ID

func (o *InMemStorages) ID() string

type MapDictionary

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

func (*MapDictionary) Add

func (o *MapDictionary) Add(key uint64, data []byte, expiration time.Time) error

func (*MapDictionary) Clean

func (o *MapDictionary) Clean(ctx context.Context) error

func (*MapDictionary) Get

func (o *MapDictionary) Get(key uint64) (Buffer, error)

type MemoryPool

type MemoryPool interface {
	Get() ([]byte, error)
	Put(d []byte)
}

func NewMemoryPool

func NewMemoryPool(sz int) MemoryPool

type PartitionedDictionary

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

func (*PartitionedDictionary) Add

func (o *PartitionedDictionary) Add(key uint64, value []byte, expiration time.Time) error

func (*PartitionedDictionary) Clean

func (*PartitionedDictionary) Get

func (o *PartitionedDictionary) Get(key uint64) (Buffer, error)

type Storages

type Storages interface {
	ID() string
	Add(key, body []byte) error
	Get(key []byte) (Buffer, error)
	Clean(ctx context.Context) error
}

func NewInMemStorages

func NewInMemStorages(
	config config.Config,
	dataDict DataDictionary,
) (Storages, error)

type SyncMapDictionary

type SyncMapDictionary struct {
	sync.Map
	// contains filtered or unexported fields
}

func (*SyncMapDictionary) Add

func (o *SyncMapDictionary) Add(key uint64, data []byte, expiration time.Time) error

func (*SyncMapDictionary) Clean

func (o *SyncMapDictionary) Clean(ctx context.Context) error

func (*SyncMapDictionary) Get

func (o *SyncMapDictionary) Get(key uint64) (Buffer, error)

Jump to

Keyboard shortcuts

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