cache

package
v0.120.25-alpha.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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