cache

package
v2.12.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2017 License: GPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToString

func ToString() string

ToString generates information about all caches initialized through this lib

Types

type Cache

type Cache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Cache is the structure that involves the map of entries. The cache provides a sync mechanism and allows multiple clients at the same time.

func NewCache

func NewCache(name string) *Cache

NewCache creates a new data cache

func NewCacheWithExpiration

func NewCacheWithExpiration(name string, lifetime time.Duration) *Cache

NewCacheWithExpiration creates a new data cache

func NewCacheWithExpirationNotifier

func NewCacheWithExpirationNotifier(name string, lifetime time.Duration, expirer ExpirationNotifier) *Cache

NewCacheWithExpirationNotifier creates a new data cache with notifier

func (*Cache) Add

func (c *Cache) Add(u interface{}, value interface{}) (err error)

Add stores an entry into the cache and updates the timestamp

func (*Cache) AddOrUpdate

func (c *Cache) AddOrUpdate(u interface{}, value interface{}) (updated bool)

AddOrUpdate adds a new value in the cache or updates the existing value if needed. If an update happens the timestamp is also updated. Returns true if key was updated.

func (*Cache) Get

func (c *Cache) Get(u interface{}) (i interface{}, err error)

Get retrieves the entry from the cache

func (*Cache) GetReset

func (c *Cache) GetReset(u interface{}, duration time.Duration) (interface{}, error)

GetReset changes the value of an entry into the cache and updates the timestamp

func (*Cache) LockedModify

func (c *Cache) LockedModify(u interface{}, add func(a, b interface{}) interface{}, increment interface{}) (interface{}, error)

LockedModify locks the data store

func (*Cache) Remove

func (c *Cache) Remove(u interface{}) (err error)

Remove removes the entry from the cache and returns error if not there

func (*Cache) RemoveWithDelay added in v1.0.58

func (c *Cache) RemoveWithDelay(u interface{}, duration time.Duration) error

RemoveWithDelay removes the entry from the cache after a certain duration

func (*Cache) SetTimeOut

func (c *Cache) SetTimeOut(u interface{}, timeout time.Duration) (err error)

SetTimeOut sets the time out of an entry to a new value

func (*Cache) SizeOf

func (c *Cache) SizeOf() int

SizeOf returns the number of elements in the cache

func (*Cache) ToString

func (c *Cache) ToString() string

ToString provides statistics about this cache

func (*Cache) Update

func (c *Cache) Update(u interface{}, value interface{}) (err error)

Update changes the value of an entry into the cache and updates the timestamp

type DataStore

type DataStore interface {
	Add(u interface{}, value interface{}) (err error)
	AddOrUpdate(u interface{}, value interface{}) bool
	Get(u interface{}) (i interface{}, err error)
	GetReset(u interface{}, duration time.Duration) (interface{}, error)
	Remove(u interface{}) (err error)
	RemoveWithDelay(u interface{}, duration time.Duration) (err error)
	LockedModify(u interface{}, add func(a, b interface{}) interface{}, increment interface{}) (interface{}, error)
	SetTimeOut(u interface{}, timeout time.Duration) (err error)
	ToString() string
}

DataStore is the interface to a datastore.

type ExpirationNotifier

type ExpirationNotifier func(c DataStore, id interface{}, item interface{})

ExpirationNotifier is a function which will be called every time a cache expires an item

Jump to

Keyboard shortcuts

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