ttl

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 3 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is a synchronised map of items that auto-expire once stale

func NewCache

func NewCache(opts ...Option) (*Cache, error)

NewCache creates a instance of the Cache struct. Argument duration stands for the existing time of item in the cache. When no argument is passed, the item will persistently existed in the cache.

func (*Cache) Count

func (cache *Cache) Count() int

Count returns the number of items in the cache

func (*Cache) Delete

func (cache *Cache) Delete(key interface{}) bool

Delete removes existing item in the cache

func (*Cache) Get

func (cache *Cache) Get(key interface{}) (interface{}, bool)

Get is a thread-safe way to lookup items Every lookup, also add the timeout of the item, hence extending it's life

func (*Cache) Keys added in v0.1.9

func (cache *Cache) Keys() []interface{}

AllKeys returns all keys store in the cache

func (*Cache) Range

func (cache *Cache) Range(f func(key, value interface{}) error)

Range calls f on every key in the map if hasEvictOnError flag is set, then a key failing f() will be deleted from the map

func (*Cache) Reset

func (cache *Cache) Reset()

Reset empties the cache

func (*Cache) Set

func (cache *Cache) Set(key, data interface{})

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

type Item

type Item struct {
	// contains filtered or unexported fields
}

Item represents a record in the cache map

type Option

type Option func(*Cache) error

func AutoExpireOption

func AutoExpireOption(ttl time.Duration) Option

func EvictOnErrorOption

func EvictOnErrorOption() Option

Jump to

Keyboard shortcuts

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