cache

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 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 TTLCache

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

TTLCache is a generic cache implementation with support for time-to-live (TTL) expiration.

func NewTTL

func NewTTL[K comparable, V any]() *TTLCache[K, V]

NewTTL creates a new TTLCache instance and starts a goroutine to periodically remove expired items every 5 seconds.

func (*TTLCache[K, V]) Get

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

Get retrieves the value associated with the given key from the cache.

func (*TTLCache[K, V]) Pop

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

Pop removes and returns the item with the specified key from the cache.

func (*TTLCache[K, V]) Remove

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

Remove removes the item with the specified key from the cache.

func (*TTLCache[K, V]) Set

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

Set adds a new item to the cache with the specified key, value, and time-to-live (TTL).

func (*TTLCache[K, V]) Stop

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

Jump to

Keyboard shortcuts

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