Documentation
¶
Overview ¶
Package cache provides a lock-free adaptive in-memory LRU cache implementation. CloxCache combines CLOCK-Pro eviction with TinyLFU admission and adaptive frequency decay.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComputeShardConfig ¶
ComputeShardConfig calculates optimal shard configuration for a target cache size
func FormatMemory ¶
FormatMemory formats bytes as human-readable string
Types ¶
type CloxCache ¶
CloxCache is a lock-free adaptive in-memory cache with CLOCK-Pro eviction. It stores generic keys of type K (string or []byte) and values of type V.
func NewCloxCache ¶
NewCloxCache creates a new cache with the given configuration
func (*CloxCache[K, V]) Close ¶
func (c *CloxCache[K, V]) Close()
Close stops background goroutines and waits for them to exit. Safe to call multiple times.
type Config ¶
type Config struct {
NumShards int // Must be power of 2
SlotsPerShard int // Must be power of 2
Capacity int // Max entries (0 = use SlotsPerShard * NumShards as default)
CollectStats bool // Enable hit/miss/eviction counters (default: false for performance)
AdaptiveDecay bool // Enable adaptive decay tuning (implies CollectStats)
}
Config holds CloxCache configuration
func ConfigFromHardware ¶
func ConfigFromHardware() Config
ConfigFromHardware creates a CloxCache config from detected hardware
func ConfigFromMemorySize ¶
ConfigFromMemorySize creates a CloxCache config for a specific memory target
func (Config) EstimateMemoryUsage ¶
EstimateMemoryUsage estimates total memory usage for a given configuration
type HardwareConfig ¶
type HardwareConfig struct {
NumCPU int // Number of logical CPUs
TotalMemory uint64 // Total system memory in bytes
CacheSize uint64 // Recommended cache size in bytes
NumShards int // Recommended number of shards
SlotsPerShard int // Recommended slots per shard
}
HardwareConfig contains detected hardware specifications
func DetectHardware ¶
func DetectHardware() HardwareConfig
DetectHardware detects system hardware and returns recommended configuration