cache

package
v0.0.0-...-36f1a77 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2016 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. For example one thread might be storing values in the cache while a parallel thread is refreshing the cache.

func NewCache

func NewCache(refresh func(val interface{}) interface{}) *Cache

NewCache creates a new data cache

func NewCacheWithExpiration

func NewCacheWithExpiration(lifetime time.Duration, length int) *Cache

NewCacheWithExpiration creates a new data cache

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{}) (err error)

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) DumpStore

func (c *Cache) DumpStore()

DumpStore prints the whole data store for debuggin

func (*Cache) Get

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

Get retrieves the entry from the cache

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) Refresh

func (c *Cache) Refresh(d time.Duration)

Refresh : will parse the cache for expired entries and validate them We will be passhing a validation function as argument here Details TBD

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) 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 Cleanable

type Cleanable interface {
	Cleanup()
}

Cleanable is an interface that could be implemented by elements being inserted in cache with expiration

type DataStore

type DataStore interface {
	Add(u interface{}, value interface{}) (err error)
	AddOrUpdate(u interface{}, value interface{}) (err error)
	Get(u interface{}) (i interface{}, err error)
	Remove(u interface{}) (err error)
	Refresh(d time.Duration)
	DumpStore()
	LockedModify(u interface{}, add func(a, b interface{}) interface{}, increment interface{}) (interface{}, error)
}

DataStore is the interface to a datastore that will evolve to hold basic values and also auto-refresh the cache. The DataStore is indexed by UUID values only

Jump to

Keyboard shortcuts

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