cache

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 7 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

	// MaxEntries is the maximum number of c entries before
	// an item is evicted. Zero means no limit.
	MaxEntries int

	// OnEvicted optionally a callback function to be
	// executed when an entry is purged from the c.
	OnEvicted func(key, value any)
	// contains filtered or unexported fields
}

c is an LRU c. It is not safe for concurrent access.

func New

func New(maxEntries int, opts ...Option) *Cache

New creates a new c. If maxEntries is zero, the c has no limit and it's assumed that eviction is done by the caller.

func (*Cache) Add

func (c *Cache) Add(key, value any)

Add adds a value to the c.

func (*Cache) Clear

func (c *Cache) Clear()

Clear purges all stored items from the c.

func (*Cache) Get

func (c *Cache) Get(key any) (value any, ok bool)

Get looks up a key's value from the c.

func (*Cache) Iterator

func (c *Cache) Iterator(do func(k, v any) error)

iterator

func (*Cache) Len

func (c *Cache) Len() int

Len returns the number of items in the c.

func (*Cache) Remove

func (c *Cache) Remove(key any) any

Remove removes the provided key from the c.

type ChanMessage

type ChanMessage struct {
	Key any `json:"k"`
}

type Entry

type Entry struct {
	Timerid uint32
	Value   any
}

type LRUCache

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

func NewLRUCache

func NewLRUCache(
	ctx context.Context,
	maxcapacity int,
	expiredTw *schedule.TimerWheel,
	OnEvicted func(k, v any)) *LRUCache

func (*LRUCache) Contains

func (l *LRUCache) Contains(key any) bool

func (*LRUCache) Get

func (l *LRUCache) Get(key any) (any, bool)

func (*LRUCache) HitRate

func (l *LRUCache) HitRate() (int, int)

func (*LRUCache) Iterator

func (l *LRUCache) Iterator(do func(k, v any) error)

func (*LRUCache) Length

func (l *LRUCache) Length() int

func (*LRUCache) Put

func (l *LRUCache) Put(key, v any, ttl time.Duration) chan time.Time

func (*LRUCache) Remove

func (l *LRUCache) Remove(key any) any

type Option

type Option func(c *Cache)

func SetEvictedRate

func SetEvictedRate(rate int) Option

Jump to

Keyboard shortcuts

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