cache

package
v0.0.79 Latest Latest
Warning

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

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

Documentation

Overview

Package cache contains cache utilities and implementations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cacher

type Cacher[T any] interface {
	Get(key string) (T, bool)
	Set(key string, value T)
}

Cacher is the interface for the cache. It provides methods to get and set

type Expiring

type Expiring[T any] interface {
	Expiration() time.Time
	Value() T
}

Expiring is an interface for an expiring cache entry It provides a method to get the expiration time and the value

func NewExpiring

func NewExpiring[T any](value T, expiration time.Time) Expiring[T]

NewExpiring creates a new Expiring entry

type ExpiringCache

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

ExpiringCache is a cache that expires entries after a certain time

func NewExpiringCache

func NewExpiringCache[T any](ctx context.Context, cfg *ExpiringCacheConfig) *ExpiringCache[T]

NewExpiringCache creates a new ExpiringCache based on the configuration If the configuration is nil, the default eviction time is 30 minutes

func (*ExpiringCache[T]) Close

func (ec *ExpiringCache[T]) Close()

Close stops the eviction routine and disallows setting new entries

func (*ExpiringCache[T]) Delete

func (ec *ExpiringCache[T]) Delete(key string)

Delete deletes the entry from the cache

func (*ExpiringCache[T]) Get

func (ec *ExpiringCache[T]) Get(key string) (T, bool)

Get returns the value of the entry and a boolean indicating if the entry exists

func (*ExpiringCache[T]) Set

func (ec *ExpiringCache[T]) Set(key string, value T)

Set sets the value of the entry

func (*ExpiringCache[T]) Size

func (ec *ExpiringCache[T]) Size() int

Size returns the number of entries in the cache. This is useful for testing purposes

type ExpiringCacheConfig

type ExpiringCacheConfig struct {
	EvictionTime time.Duration
}

ExpiringCacheConfig is the configuration for the ExpiringCache

Jump to

Keyboard shortcuts

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