cache

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCacheIsNotFound = errors.New("cache is not found")
	ErrCacheWasExpired = errors.New("cache was expired")
)
View Source
var DefaultUpdateTimeTickInterval = time.Millisecond * 300

Functions

This section is empty.

Types

type Cache

type Cache[K comparable, V any] interface {
	Get(K) (V, error)
	Set(K, V)
	Delete(K)
	Contains(K) bool
	Stop()
}

func NewCache

func NewCache[K comparable, V any](opt ...Option) Cache[K, V]

type EvictCallback

type EvictCallback func(any, any)

type LruCache

type LruCache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func (*LruCache[K, V]) Contains

func (c *LruCache[K, V]) Contains(key K) bool

func (*LruCache[K, V]) Delete

func (c *LruCache[K, V]) Delete(key K)

func (*LruCache[K, V]) Get

func (c *LruCache[K, V]) Get(key K) (value V, err error)

func (*LruCache[K, V]) Set

func (c *LruCache[K, V]) Set(key K, value V)

func (*LruCache[K, V]) Stop

func (c *LruCache[K, V]) Stop()

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithBackgroundCheckCache

func WithBackgroundCheckCache() Option

func WithDeleteExpiredCacheOnGet

func WithDeleteExpiredCacheOnGet() Option

func WithEvictCallback

func WithEvictCallback(fn EvictCallback) Option

func WithExpiration

func WithExpiration(expiration time.Duration) Option

func WithGoTimeNow

func WithGoTimeNow() Option

func WithInterval

func WithInterval(interval time.Duration) Option

func WithMaxSize

func WithMaxSize(maxSize int) Option

func WithUpdateCacheExpirationOnGet

func WithUpdateCacheExpirationOnGet() Option

type OptionFunc

type OptionFunc func(o *options)

Jump to

Keyboard shortcuts

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