interview

package module
v0.0.0-...-7d590e6 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

README

providers

Package implements abstract data provider with alternative implementations of storage engine.

  • unlimited in-memory storage without any constraints.
  • hot storage with limited capacity and LRU eviction policy.
  • ttl storage with limited capacity and TTL eviction policy.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[K comparable, V any] struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewCache

func NewCache[K comparable, V any](
	storage Storage[K, V],
	gcPeriod time.Duration,
) *Cache[K, V]

func (*Cache[K, V]) Clear

func (that *Cache[K, V]) Clear()

func (*Cache[K, V]) Get

func (that *Cache[K, V]) Get(key K) StorageEntry[V]

func (*Cache[K, V]) Set

func (that *Cache[K, V]) Set(key K, val *V)

type Fetcher

type Fetcher[K comparable, V any] interface {
	Fetch(key K) (*V, error)
}

type HotStorage

type HotStorage[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewHotStorage

func NewHotStorage[K comparable, V any](
	capacity int,
) *HotStorage[K, V]

func (*HotStorage[K, V]) Cleanup

func (that *HotStorage[K, V]) Cleanup() []K

func (*HotStorage[K, V]) Clear

func (that *HotStorage[K, V]) Clear()

func (*HotStorage[K, V]) Get

func (that *HotStorage[K, V]) Get(key K) (*V, bool)

func (*HotStorage[K, V]) Len

func (that *HotStorage[K, V]) Len() int

func (*HotStorage[K, V]) Set

func (that *HotStorage[K, V]) Set(key K, val *V)

type Provider

type Provider[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewProvider

func NewProvider[K comparable, V any](
	fetcher Fetcher[K, V],
	storage ProviderStorage[K, V],
) *Provider[K, V]

func (*Provider[K, V]) Get

func (that *Provider[K, V]) Get(key K) (*V, error)

type ProviderStorage

type ProviderStorage[K comparable, V any] interface {
	Get(key K) StorageEntry[V]
}

type Storage

type Storage[K comparable, V any] interface {
	Set(key K, val *V)
	Get(key K) (*V, bool)
	Clear()
	Cleanup() []K
	Len() int
}

type StorageEntry

type StorageEntry[V any] interface {
	Get() (*V, bool)
	Set(val *V)
}

type TTLStorage

type TTLStorage[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewTTLStorage

func NewTTLStorage[K comparable, V any](
	ttl time.Duration,
) *TTLStorage[K, V]

func (*TTLStorage[K, V]) Cleanup

func (that *TTLStorage[K, V]) Cleanup() []K

func (*TTLStorage[K, V]) Clear

func (that *TTLStorage[K, V]) Clear()

func (*TTLStorage[K, V]) Get

func (that *TTLStorage[K, V]) Get(key K) (*V, bool)

func (*TTLStorage[K, V]) Len

func (that *TTLStorage[K, V]) Len() int

func (*TTLStorage[K, V]) Set

func (that *TTLStorage[K, V]) Set(key K, val *V)

type UnlimitedStorage

type UnlimitedStorage[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewUnlimitedStorage

func NewUnlimitedStorage[K comparable, V any]() *UnlimitedStorage[K, V]

func (*UnlimitedStorage[K, V]) Cleanup

func (that *UnlimitedStorage[K, V]) Cleanup() []K

func (*UnlimitedStorage[K, V]) Clear

func (that *UnlimitedStorage[K, V]) Clear()

func (*UnlimitedStorage[K, V]) Get

func (that *UnlimitedStorage[K, V]) Get(key K) (*V, bool)

func (*UnlimitedStorage[K, V]) Len

func (that *UnlimitedStorage[K, V]) Len() int

func (*UnlimitedStorage[K, V]) Set

func (that *UnlimitedStorage[K, V]) Set(key K, val *V)

Jump to

Keyboard shortcuts

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