cache

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 6 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[K comparable, T any] interface {
	Get(key K) (T, bool, error)
	Set(key K, value T) error
	Del(key K) error
	Clear() error
	Len() (int64, error)
}

func NewInMemoryCache

func NewInMemoryCache[K comparable, T any](name string, ttl time.Duration) (Cache[K, T], error)

NewInMemoryCache creates a new in-memory cache with the given name and TTL. It is a strong reference cache, meaning that values are kept in memory until explicitly deleted or the cache is cleared. It uses a sync.Map for thread-safe operations. Expired entries are removed upon access, so to keep the cache size optimal, periodic cleanup is recommended.

func NewInMemoryWeakCache added in v0.7.0

func NewInMemoryWeakCache[K comparable, T any](name string, ttl time.Duration) (Cache[K, T], error)

NewInMemoryWeakCache creates a new in-memory weak cache with the given name and TTL. It serializes values using msgpack to remove the strong references, but this incurs serialization overhead.

Jump to

Keyboard shortcuts

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