cache

package
v0.0.0-...-f409b5d Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ICache

type ICache[K comparable, V any] interface {
	Set(key K, value V, ttl ...time.Duration)
	Get(key K) (V, bool)
	Remove(key K)
	Pop(key K) (V, bool)
}

ICache defines the methods for a generic key-value cache.

func New

func New[K comparable, V any](cleanInterval ...time.Duration) ICache[K, V]

New creates a new TTLCache instance

type TTLCache

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

TTLCache is a generic in-memory key-value cache with optional TTL support.

func (*TTLCache[K, V]) Get

func (c *TTLCache[K, V]) Get(key K) (V, bool)

Get retrieves the value associated with the given key.

func (*TTLCache[K, V]) Pop

func (c *TTLCache[K, V]) Pop(key K) (V, bool)

Pop removes and returns the value associated with the specified key.

func (*TTLCache[K, V]) Remove

func (c *TTLCache[K, V]) Remove(key K)

Remove deletes the key-value pair with the specified key.

func (*TTLCache[K, V]) Set

func (c *TTLCache[K, V]) Set(key K, value V, ttl ...time.Duration)

Set adds or updates a key-value pair in the cache with optional TTL, if no TTL is specified the item will not expire.

Jump to

Keyboard shortcuts

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