cache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheManager

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

CacheManager provides TTL-based caching with thread-safety and persistence

func NewCacheManager

func NewCacheManager(path string, config Config) (*CacheManager, error)

NewCacheManager creates a new cache manager with the specified configuration

func (*CacheManager) Clear

func (cm *CacheManager) Clear()

Clear removes all entries from the cache

func (*CacheManager) Close

func (cm *CacheManager) Close() error

Close shuts down the cache manager and saves to disk

func (*CacheManager) Get

func (cm *CacheManager) Get(key string) interface{}

Get retrieves a value from the cache by key

func (*CacheManager) Save

func (cm *CacheManager) Save() error

Save persists the cache to disk

func (*CacheManager) Set

func (cm *CacheManager) Set(key string, value interface{})

Set stores a value in the cache with the given key

func (*CacheManager) Stats

func (cm *CacheManager) Stats() map[string]interface{}

Stats returns cache performance statistics

type CacheStats

type CacheStats struct {
	Hits   int `json:"hits"`
	Misses int `json:"misses"`
	Size   int `json:"size"`
}

CacheStats tracks cache performance metrics

type Config

type Config struct {
	MaxSize       int           // Maximum number of entries
	TTL           time.Duration // Time to live for entries
	CleanupPeriod time.Duration // How often to run cleanup (defaults to TTL/4)
}

Config holds cache configuration

type Entry

type Entry struct {
	Key        string      `json:"key"`
	Value      interface{} `json:"value"`
	CreatedAt  time.Time   `json:"created_at"`
	AccessedAt time.Time   `json:"accessed_at"`
}

Entry represents a cached entry with metadata

Jump to

Keyboard shortcuts

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