cache

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 6 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 CacheEntry

type CacheEntry struct {
	Key        string      `json:"key"`
	Value      interface{} `json:"value"`
	Expiration time.Time   `json:"expiration"`
	Created    time.Time   `json:"created"`
	LastAccess time.Time   `json:"last_access"`
	HitCount   int64       `json:"hit_count"`
	Size       int64       `json:"size"`
}

CacheEntry represents a single cache entry

type CacheMetrics

type CacheMetrics struct {
	Hits      int64
	Misses    int64
	Sets      int64
	Deletes   int64
	Evictions int64
	TotalSize int64
	ItemCount int
	// contains filtered or unexported fields
}

CacheMetrics tracks cache performance

type GlobalCache

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

GlobalCache provides thread-safe caching with TTL and persistence

func NewGlobalCache

func NewGlobalCache(maxSize int64, defaultTTL time.Duration, persistPath string) *GlobalCache

NewGlobalCache creates a new global cache instance

func (*GlobalCache) Clear

func (gc *GlobalCache) Clear()

Clear removes all items from the cache

func (*GlobalCache) Close

func (gc *GlobalCache) Close()

Close stops the cleanup goroutine and saves cache to disk

func (*GlobalCache) Delete

func (gc *GlobalCache) Delete(key string) bool

Delete removes an item from the cache

func (*GlobalCache) Get

func (gc *GlobalCache) Get(key string) (interface{}, bool)

Get retrieves a value from the cache

func (*GlobalCache) GetMetrics

func (gc *GlobalCache) GetMetrics() CacheMetrics

GetMetrics returns cache metrics

func (*GlobalCache) GetWithAge

func (gc *GlobalCache) GetWithAge(key string) (interface{}, bool, time.Duration)

GetWithAge returns a value and its age

func (*GlobalCache) HitRate

func (gc *GlobalCache) HitRate() float64

HitRate returns the cache hit rate

func (*GlobalCache) Set

func (gc *GlobalCache) Set(key string, value interface{}, ttl ...time.Duration) error

Set stores a value in the cache with the default TTL

Jump to

Keyboard shortcuts

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