ttl

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 License: MIT 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 a synchronised map of items that auto-expire once stale

func NewCache

func NewCache(opts ...CacheOption) *Cache

NewCache create a K-V cache

func (*Cache) Close

func (c *Cache) Close()

Close remove all data from Cache and exit cleanup. Cache cannot use any more after close

func (*Cache) Get

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

Get is a thread-safe way to lookup items. Every lookup, also hence extending it's life if ttl is enabled

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 interface{})

Remove removes item from Cache

func (*Cache) Set

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

Set is a thread-safe way to set item to the map

type CacheOption

type CacheOption func(*Cache)

func CacheWithLRU

func CacheWithLRU(cap int) CacheOption

func CacheWithTTL

func CacheWithTTL(d time.Duration) CacheOption

type Counter

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

func NewCounter

func NewCounter(d time.Duration) *Counter

NewCounter create a counter with TTL records

func (*Counter) Close added in v0.0.8

func (c *Counter) Close()

Close remove all data from Counter and exit cleanup. Counter cannot use any more after close

func (*Counter) Incr

func (c *Counter) Incr()

func (*Counter) Len

func (c *Counter) Len() int

type Item

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

Jump to

Keyboard shortcuts

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