cache

package
v1.0.57 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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() *Cache

NewCache creates a new data cache

func NewCacheWithExpiration

func NewCacheWithExpiration(lifetime time.Duration) *Cache

NewCacheWithExpiration creates a new data cache

func NewCacheWithExpirationNotifier

func NewCacheWithExpirationNotifier(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{})

AddOrUpdate adds a new value in the cache or updates the existing value if needed. If an update happens the timestamp is also 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) 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) 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{})
	Get(u interface{}) (i interface{}, err error)
	GetReset(u interface{}, duration time.Duration) (interface{}, error)
	Remove(u interface{}) (err error)
	LockedModify(u interface{}, add func(a, b interface{}) interface{}, increment interface{}) (interface{}, error)
	SetTimeOut(u interface{}, timeout time.Duration) (err error)
}

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