cache

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2025 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 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