Documentation ¶
Index ¶
Constants ¶
const (
NoPurge = time.Duration(0)
)
Variables ¶
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 ¶
New creates a Dam that purges every duration. If set to NoPurge or value less than zero the Dam will never purge.
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) 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.
type FetchFunc ¶
type FetchFunc func() (interface{}, error)
FetchFunc represents a function that fetches value to be stored in Dam.
type Marshallable ¶
Marshallable represents a struct (typicaly a profobuf struct) that can be serialized into byte slice.