Documentation ¶
Index ¶
- Constants
- Variables
- type Dam
- func (d *Dam) Delete(key Marshallable) error
- func (d *Dam) Load(key Marshallable) (interface{}, error)
- func (d *Dam) LoadOrStore(key Marshallable, fetch FetchFunc) (interface{}, error)
- func (d *Dam) Lock()
- func (d *Dam) Purge()
- func (d *Dam) Range(f func(value interface{}) bool)
- func (d *Dam) Size() int
- func (d *Dam) Stop()
- func (d *Dam) Store(key Marshallable, value interface{}) error
- func (d *Dam) Unlock()
- type FetchFunc
- type Marshallable
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) 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) Range ¶ added in v0.2.0
Range ranges over existing entries in a Dam. Range does not represent snapshot of Dam. Range returns if f returns false.
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.
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.