inmemory

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 License: GPL-3.0, GPL-3.0-or-later Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ExpireNever is the TTL value to use for an object that should never expire
	ExpireNever = time.Duration(-1)
)

Variables

View Source
var (
	// ErrorKeyUsed is returned for an attempt to store an object using an existing key is made
	ErrorKeyUsed = errors.New("the key specified is in use")

	// ErrorStorageFull is returned when the max item limit for object storage has been reached
	ErrorStorageFull = errors.New("storage limit has been reached")
)

Functions

This section is empty.

Types

type Object

type Object struct {
	Data    []byte
	Expires *time.Time
}

Object is the structure that holds an item that will be stored in memory. It can hold a TTL so that

type Storage

type Storage struct {
	MaxItems int
	TTL      time.Duration
	// contains filtered or unexported fields
}

Storage implements StoreRetriever for inmemory storage

func New

func New(expiry time.Duration, scrubInterval time.Duration, maxItems int) *Storage

New initialises a new in memory store expiry sets the time before an object is deleted scrubInterval is the interval at which the scrubber will run to clean up expired items

func (*Storage) Contains

func (s *Storage) Contains(key string) bool

Contains implements the Contains function to satisfy StoreRetriever

func (*Storage) Retrieve

func (s *Storage) Retrieve(key string) ([]byte, error)

Retrieve implements the Retrieve function to satisfy StoreRetriever

func (*Storage) Store

func (s *Storage) Store(key string, data []byte) error

Store implements the Store function to satisfy StoreRetriever

Jump to

Keyboard shortcuts

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