tcache

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2021 License: Apache-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 {
	// LifeTime is lifespan for all entries
	LifeTime uint64
	// if exceed MaxLifeTime will force update
	MaxLifeTime uint64
	MaxEntries  int

	sync.RWMutex
	// contains filtered or unexported fields
}

1. Keep entries available, trigger a update-key operation instead of purging entries out-of-date. 2. concurrent access safe 3. LRU

func NewCache

func NewCache(lifeTime, maxlifeTime uint64, maxEntries int, updateKeyFunc UpdateKeyFunc) *Cache

NewCache creates a new Cache. auto flush cache to file if flushFile not "" and flushInterval > 0 for flush cache value must jsonable

func (*Cache) Add

func (c *Cache) Add(key string, value interface{})

Add adds a value to the cache. Update born and state if exsit

func (*Cache) Get

func (c *Cache) Get(key string) (interface{}, error)

Get looks up a key's value from the cache. if entry is nil will block util get value if entry is out of date will return old value and trigger an upate-key operation if needed

func (*Cache) Len

func (c *Cache) Len() int

Len returns the number of items in the cache.

func (*Cache) Remove

func (c *Cache) Remove(key string)

Remove removes the provided key from the cache.

type UpdateKeyFunc

type UpdateKeyFunc func(key string) (value interface{}, err error)

Jump to

Keyboard shortcuts

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