cache

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxContentEntries = 400
	DefaultMaxSymbolEntries  = 400
	DefaultMaxParserEntries  = 200
	DefaultTTL               = 2 * time.Hour
	DefaultCleanupInterval   = 10 * time.Minute
	EstimatedBytesPerEntry   = 322.0
)

Cache configuration constants

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheConfig

type CacheConfig struct {
	MaxContentEntries int
	MaxSymbolEntries  int
	MaxParserEntries  int
	TTL               time.Duration
	EnableContent     bool
	EnableSymbol      bool
	EnableParser      bool
	AutoCleanup       bool
	CleanupInterval   time.Duration
}

CacheConfig defines configuration options

func DefaultCacheConfig

func DefaultCacheConfig() CacheConfig

DefaultCacheConfig returns default configuration

type CacheInfo

type CacheInfo struct {
	MaxEntries    int
	TTL           time.Duration
	EnableContent bool
	EnableSymbol  bool
	Stats         CacheStats
	Status        string
}

CacheInfo provides cache information

type CacheStats

type CacheStats struct {
	Hits              int64
	Misses            int64
	Evictions         int64
	TotalRequests     int64
	HitRate           float64
	ContentEntries    int
	SymbolEntries     int
	ParserEntries     int
	TotalEntries      int
	CreatedAt         time.Time
	LastCleanup       time.Time
	Uptime            time.Duration
	ParserHits        int64
	ParserHitRate     float64
	EstimatedMemoryKB float64
}

CacheStats holds cache statistics

type CachedMetrics

type CachedMetrics struct {
	Data        interface{}
	CachedAt    int64 // Unix nano for atomic compare
	AccessCount int64 // Atomic counter
	ContentHash string
	SymbolName  string
	FileID      int
}

CachedMetrics represents cached metrics data

type MetricsCache

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

MetricsCache provides lock-free caching using sync.Map

func NewMetricsCache

func NewMetricsCache(config CacheConfig) *MetricsCache

NewMetricsCache creates a new cache

func (*MetricsCache) CleanExpired

func (mc *MetricsCache) CleanExpired() int

CleanExpired removes expired entries

func (*MetricsCache) Clear

func (mc *MetricsCache) Clear()

Clear removes all entries and resets statistics

func (*MetricsCache) Get

func (mc *MetricsCache) Get(content []byte, fileID int, symbolName string) interface{}

Get retrieves cached metrics

func (*MetricsCache) GetCacheInfo

func (mc *MetricsCache) GetCacheInfo() CacheInfo

GetCacheInfo returns cache configuration and status

func (*MetricsCache) GetWithLanguage

func (mc *MetricsCache) GetWithLanguage(content []byte, fileID int, symbolName string, language string) interface{}

GetWithLanguage retrieves with parser cache priority

func (*MetricsCache) GetWithPrecomputedHash

func (mc *MetricsCache) GetWithPrecomputedHash(contentHash [32]byte, fileID int, symbolName string) interface{}

GetWithPrecomputedHash retrieves using pre-computed hash

func (*MetricsCache) Put

func (mc *MetricsCache) Put(content []byte, fileID int, symbolName string, metrics interface{})

Put stores metrics in cache with size limiting

func (*MetricsCache) PutWithLanguage

func (mc *MetricsCache) PutWithLanguage(content []byte, fileID int, symbolName string, language string, metrics interface{})

PutWithLanguage stores with parser cache and size limiting

func (*MetricsCache) SetMaxEntries

func (mc *MetricsCache) SetMaxEntries(maxEntries int)

SetMaxEntries updates max entries (no-op for sync.Map, kept for API compatibility)

func (*MetricsCache) Stats

func (mc *MetricsCache) Stats() CacheStats

Stats returns cache statistics

func (*MetricsCache) UpdateTTL

func (mc *MetricsCache) UpdateTTL(ttl time.Duration)

UpdateTTL updates TTL and cleans expired entries

Jump to

Keyboard shortcuts

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