basic

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTTLSeconds = int64(3600)
	DefaultMaxCost    = uint64(1000)
	DefaultFrequency  = time.Hour
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicCache

type BasicCache[T any] struct {
	// contains filtered or unexported fields
}

func NewCache

func NewCache[T any](options ...Option) (*BasicCache[T], error)

func (*BasicCache[T]) Close

func (c *BasicCache[T]) Close()

func (*BasicCache[T]) Delete

func (c *BasicCache[T]) Delete(key string)

func (*BasicCache[T]) Get

func (c *BasicCache[T]) Get(key string) (T, bool)

func (*BasicCache[T]) Set

func (c *BasicCache[T]) Set(key string, value T, cost uint64, expiresInSeconds int64) error

func (*BasicCache[T]) SetWithDefaultTTL added in v1.2.1

func (c *BasicCache[T]) SetWithDefaultTTL(key string, value T, cost uint64) error

type CacheItem

type CacheItem[T any] struct {
	// contains filtered or unexported fields
}

type Config

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

type EvictItemFunc

type EvictItemFunc func(key string, cost uint64, expiryTime int64, now int64) bool

EvictItemFunc can be used to tell the cache not to evict an item based on the provided, key, value or expiryTime.

type Option

type Option func(*Config)

func WithCleanupFrequency

func WithCleanupFrequency(cleanupFrequency time.Duration) Option

func WithEvictionFunction

func WithEvictionFunction(f EvictItemFunc) Option

func WithMaxCost

func WithMaxCost(maxCost uint64) Option

func WithTTL added in v1.2.1

func WithTTL(ttl time.Duration) Option

Jump to

Keyboard shortcuts

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