trireme-lib: go.aporeto.io/trireme-lib/utils/cache Index | Files

package cache

import "go.aporeto.io/trireme-lib/utils/cache"

Index

Package Files

cache.go

func ToString Uses

func ToString() string

ToString generates information about all caches initialized through this lib

type Cache Uses

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 Uses

func NewCache(name string) *Cache

NewCache creates a new data cache

func NewCacheWithExpiration Uses

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

NewCacheWithExpiration creates a new data cache

func NewCacheWithExpirationNotifier Uses

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

NewCacheWithExpirationNotifier creates a new data cache with notifier

func (*Cache) Add Uses

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

Add stores an entry into the cache and updates the timestamp

func (*Cache) AddOrUpdate Uses

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 Uses

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

Get retrieves the entry from the cache

func (*Cache) GetReset Uses

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) KeyList Uses

func (c *Cache) KeyList() []interface{}

KeyList returns all the keys that are currently stored in the cache.

func (*Cache) LockedModify Uses

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

LockedModify locks the data store

func (*Cache) Remove Uses

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

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

func (*Cache) RemoveWithDelay Uses

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

RemoveWithDelay removes the entry from the cache after a certain duration

func (*Cache) SetTimeOut Uses

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 Uses

func (c *Cache) SizeOf() int

SizeOf returns the number of elements in the cache

func (*Cache) ToString Uses

func (c *Cache) ToString() string

ToString provides statistics about this cache

func (*Cache) Update Uses

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 Uses

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)
    KeyList() []interface{}
    ToString() string
}

DataStore is the interface to a datastore.

type ExpirationNotifier Uses

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

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

Package cache imports 5 packages (graph) and is imported by 28 packages. Updated 2018-11-14. Refresh now. Tools for package owners.