dam

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2019 License: CC0-1.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoPurge = time.Duration(0)
)

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
)

Functions

This section is empty.

Types

type Dam

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

Dam represents instance of purgeable cache.

func New

func New(duration time.Duration) *Dam

New creates a Dam that purges every duration. If set to NoPurge or value less than zero the Dam will never purge.

func (*Dam) Delete added in v0.3.0

func (d *Dam) Delete(key Marshallable) error

Delete deletes entry in Dam for the key.

func (*Dam) Load

func (d *Dam) Load(key Marshallable) (interface{}, error)

Load returns existing value stored for the key. If no value is present it returns ErrNotFound as the error.

func (*Dam) LoadOrStore

func (d *Dam) LoadOrStore(key Marshallable, fetch FetchFunc) (interface{}, error)

LoadOrStore returns existing value for the key if present. If the is no value it will call fetch function and set given value for the key. Note: fetch function is supposed to be called as a closure and fetch value for the key.

func (*Dam) Lock added in v0.8.0

func (d *Dam) Lock()

Lock locks Dam d for writing.

func (*Dam) Purge

func (d *Dam) Purge()

Purge purges Dam.

func (*Dam) Range added in v0.2.0

func (d *Dam) Range(f func(value interface{}) bool)

Range ranges over existing entries in a Dam. Range does not represent snapshot of Dam. Range returns if f returns false.

func (*Dam) Size added in v0.7.0

func (d *Dam) Size() int

Size returns current number of elements stored in Dam.

func (*Dam) Stop

func (d *Dam) Stop()

Stop stops purging of the Dam and allows underlying resources to be freed.

func (*Dam) Store

func (d *Dam) Store(key Marshallable, value interface{}) error

Store sets the value for a key.

func (*Dam) Unlock added in v0.8.0

func (d *Dam) Unlock()

Unlock unlocks Dam d for writing.

type FetchFunc

type FetchFunc func() (interface{}, error)

FetchFunc represents a function that fetches value to be stored in Dam.

type Marshallable

type Marshallable interface {
	Marshal() ([]byte, error)
}

Marshallable represents a struct (typicaly a profobuf struct) that can be serialized into byte slice.

func Key added in v0.6.0

func Key(v interface{}) Marshallable

Key converets v into a Marshallable using all fields. If v is already Marshallable, Key will return it.

Jump to

Keyboard shortcuts

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