cache

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[V any] struct {
	// contains filtered or unexported fields
}

Cache is a generic key‑value store where each entry expires after a fixed TTL. Key is always string; value is any comparable type V.

Expired entries are lazily removed when Get is called. Use Remove for proactive deletion. Safe for concurrent use.

func New

func New[V any](ttl time.Duration) *Cache[V]

New creates a Cache with the given TTL.

func (*Cache[V]) Get

func (c *Cache[V]) Get(key string) *V

Get returns a copy of the value for key, or nil if not found or expired.

func (*Cache[V]) Put

func (c *Cache[V]) Put(key string, value V)

Put inserts or overwrites the value for key, resetting the expiration timer.

func (*Cache[V]) Remove

func (c *Cache[V]) Remove(key string)

Remove deletes the entry for key. No‑op if key does not exist.

Jump to

Keyboard shortcuts

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