cache

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheStats

type CacheStats struct {
	Hits      uint64
	Misses    uint64
	Evictions uint64
	Size      int
	Capacity  int
}

CacheStats contains cache statistics.

type LRUCache

type LRUCache struct {
	// contains filtered or unexported fields
}

LRUCache provides a thread-safe LRU cache with optional TTL.

func NewLRUCache

func NewLRUCache(capacity int) *LRUCache

NewLRUCache creates a new LRU cache with the specified capacity.

func (*LRUCache) Clear

func (c *LRUCache) Clear()

Clear removes all items from the cache.

func (*LRUCache) Delete

func (c *LRUCache) Delete(key string)

Delete removes a key from the cache.

func (*LRUCache) Get

func (c *LRUCache) Get(key string) (interface{}, bool)

Get retrieves a value from the cache.

func (*LRUCache) GetOrCreate

func (c *LRUCache) GetOrCreate(key string, createFunc func() interface{}) interface{}

GetOrCreate retrieves a value from the cache or creates it using the provided function.

func (*LRUCache) Len

func (c *LRUCache) Len() int

Len returns the number of items in the cache.

func (*LRUCache) Put

func (c *LRUCache) Put(key string, value interface{}, ttl time.Duration)

Put adds or updates a value in the cache.

func (*LRUCache) Stats

func (c *LRUCache) Stats() CacheStats

Stats returns cache statistics.

func (*LRUCache) Warmup

func (c *LRUCache) Warmup(keys []string, factory func(key string) interface{})

Warmup pre-populates the cache with the given keys using the provided factory function. This helps avoid cold-start allocation spikes in high-traffic applications.

Jump to

Keyboard shortcuts

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