ttlcache

package
v0.1.27 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 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 {
	Mutex       sync.RWMutex
	Ttl         time.Duration
	TtlInterval time.Duration
	Items       map[string]*Item
}

Cache is a synchronised map of Items that auto-expire once stale https://github.com/microsoftarchive/ttlcache @Description:

func NewCache

func NewCache(duration time.Duration, interval time.Duration) *Cache

NewCache is a helper to create instance of the Cache struct

func (*Cache) ContainsKey

func (cache *Cache) ContainsKey(key string) (found bool)

Set is a thread-safe way to add new Items to the map

func (*Cache) ContainsKeyAndUpdate added in v0.1.14

func (cache *Cache) ContainsKeyAndUpdate(key string, value string) (found bool)

Set is a thread-safe way to add new Items to the map

func (*Cache) Count

func (cache *Cache) Count() int

Count returns the number of Items in the cache (helpful for tracking memory leaks)

func (*Cache) Get

func (cache *Cache) Get(key string) (data string, found bool)

Get is a thread-safe way to lookup Items Every lookup, also touches the item, hence extending it's life

func (*Cache) Set

func (cache *Cache) Set(key string, data string)

Set is a thread-safe way to add new Items to the map

func (*Cache) SetWithTtl added in v0.1.14

func (cache *Cache) SetWithTtl(key string, data string, duration time.Duration)

Set is a thread-safe way to add new Items to the map

func (*Cache) ToStringMap added in v0.1.13

func (cache *Cache) ToStringMap() map[string]string

ToStringMap @Description: convert to string map @receiver cache @return map[string]string

func (*Cache) ToValueArray added in v0.1.25

func (cache *Cache) ToValueArray() []string

ToValueArray @Description: convert values to array @receiver cache @return []string

type Item

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

MapItem represents a record in the cache map

Jump to

Keyboard shortcuts

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