Help us shape the future of Go! Take the 2026 Go Developer Survey

ttlcache

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 4 Imported by: 2

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 an efficient cache with a TTL.

func NewCache

func NewCache[V any](opts CacheOptions) *Cache[V]

NewCache returns a new cache with a TTL.

func (*Cache[V]) Cleanup

func (c *Cache[V]) Cleanup()

Cleanup removes all expired entries from the cache.

func (*Cache[V]) Delete

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

Delete an item from the cache

func (*Cache[V]) Get

func (c *Cache[V]) Get(key string) (v V, ok bool)

Get returns an item from the cache. Items that have expired are not returned.

func (*Cache[V]) Reset

func (c *Cache[V]) Reset()

Reset removes all entries from the cache.

func (*Cache[V]) Set

func (c *Cache[V]) Set(key string, val V, ttl int64)

Set an item in the cache.

func (*Cache[V]) Stop

func (c *Cache[V]) Stop()

Stop the cache, stopping the background garbage collection process.

type CacheOptions

type CacheOptions struct {
	// Initial size for the cache.
	// This is optional, and if empty will be left to the underlying library to decide.
	InitialSize int32

	// Interval to perform garbage collection.
	// This is optional, and defaults to 150s (2.5 minutes).
	CleanupInterval time.Duration

	// Maximum TTL value in seconds, if greater than 0
	MaxTTL int64
	// contains filtered or unexported fields
}

CacheOptions are options for NewCache.

Jump to

Keyboard shortcuts

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