cache

package
v5.0.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: GPL-3.0 Imports: 5 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[K Key, V Value] struct {
	// contains filtered or unexported fields
}

Cache is a simple map cache that stores values in memory. It is safe for concurrent use.

func New

func New[K Key, V Value](opts Opts) *Cache[K, V]

New initializes a Cache. The minimum size is 1024. cleanerInterval specifies the interval that Cache scans and discards expired values. If cleanerInterval <= 0, a default interval will be used.

func (*Cache[K, V]) Close

func (c *Cache[K, V]) Close() error

Close closes the inner cleaner of this cache.

func (*Cache[K, V]) Flush

func (c *Cache[K, V]) Flush()

Flush removes all stored entries from this cache.

func (*Cache[K, V]) Get

func (c *Cache[K, V]) Get(key K) (v V, expirationTime time.Time, ok bool)

func (*Cache[K, V]) Len

func (c *Cache[K, V]) Len() int

Len returns the current size of this cache.

func (*Cache[K, V]) Range

func (c *Cache[K, V]) Range(f func(key K, v V, expirationTime time.Time) error) error

Range calls f through all entries. If f returns an error, the same error will be returned by Range.

func (*Cache[K, V]) Store

func (c *Cache[K, V]) Store(key K, v V, expirationTime time.Time)

Store stores this kv in cache. If expirationTime is before time.Now(), Store is an noop.

type Key

type Key interface {
	concurrent_lru.Hashable
}

type Opts

type Opts struct {
	Size            int
	CleanerInterval time.Duration
}

type Value

type Value interface {
	any
}

Jump to

Keyboard shortcuts

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