Documentation
¶
Overview ¶
Package resourcecache provides a thread-safe LRU cache with memory-based eviction for caching parsed HCL resources.
Index ¶
- type Cache
- type CacheConfig
- type CacheStats
- type MetricsCollector
- type ResourceCache
- func (rc *ResourceCache) Clear()
- func (rc *ResourceCache) Get(name string) (interface{}, bool)
- func (rc *ResourceCache) GetResource(name string) (modconfig.HclResource, bool)
- func (rc *ResourceCache) Invalidate(name string)
- func (rc *ResourceCache) InvalidateAll(predicate func(string) bool)
- func (rc *ResourceCache) Keys() []string
- func (rc *ResourceCache) Len() int
- func (rc *ResourceCache) Put(name string, value interface{})
- func (rc *ResourceCache) PutResource(name string, resource modconfig.HclResource)
- func (rc *ResourceCache) Stats() CacheStats
- type Sizer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a thread-safe LRU cache with memory-based eviction
func New ¶
func New(config CacheConfig) *Cache
New creates a new LRU cache with the given configuration
func (*Cache) Get ¶
Get retrieves an item from the cache. Returns the value and true if found, nil and false otherwise.
type CacheConfig ¶
type CacheConfig struct {
MaxMemoryBytes int64 // Maximum memory usage (default: 50MB)
MaxEntries int // Maximum entries (0 = unlimited, use memory only)
TTL time.Duration // Time-to-live for entries (0 = no expiry)
}
CacheConfig configures the LRU cache
func DefaultConfig ¶
func DefaultConfig() CacheConfig
DefaultConfig returns sensible defaults for the cache
type CacheStats ¶
type CacheStats struct {
Entries int // Number of entries in cache
MemoryBytes int64 // Current memory usage
MaxMemory int64 // Maximum memory limit
Hits int64 // Number of cache hits
Misses int64 // Number of cache misses
Evictions int64 // Number of evicted entries
HitRate float64 // Hit rate (0.0 - 1.0)
}
CacheStats holds cache performance statistics
type MetricsCollector ¶
type MetricsCollector struct {
// contains filtered or unexported fields
}
MetricsCollector tracks cache performance over time
func NewMetricsCollector ¶
func NewMetricsCollector(cache *Cache, interval time.Duration) *MetricsCollector
NewMetricsCollector creates a new metrics collector for the given cache
func (*MetricsCollector) Collect ¶
func (m *MetricsCollector) Collect()
Collect takes a snapshot of current cache stats
func (*MetricsCollector) JSON ¶
func (m *MetricsCollector) JSON() ([]byte, error)
JSON returns the current stats as JSON
func (*MetricsCollector) Report ¶
func (m *MetricsCollector) Report() string
Report returns a human-readable report of cache statistics
func (*MetricsCollector) ResetStats ¶
func (m *MetricsCollector) ResetStats()
ResetStats resets the hit/miss/eviction counters (for testing or periodic reset)
func (*MetricsCollector) Samples ¶
func (m *MetricsCollector) Samples() []CacheStats
Samples returns all collected samples
func (*MetricsCollector) Start ¶
func (m *MetricsCollector) Start()
Start begins periodic metrics collection
func (*MetricsCollector) Stop ¶
func (m *MetricsCollector) Stop()
Stop stops periodic metrics collection
type ResourceCache ¶
type ResourceCache struct {
// contains filtered or unexported fields
}
ResourceCache specializes Cache for HCL resources with type-safe access methods
func NewResourceCache ¶
func NewResourceCache(config CacheConfig) *ResourceCache
NewResourceCache creates a cache for parsed resources
func (*ResourceCache) Get ¶
func (rc *ResourceCache) Get(name string) (interface{}, bool)
Get retrieves any cached value by key (generic access)
func (*ResourceCache) GetResource ¶
func (rc *ResourceCache) GetResource(name string) (modconfig.HclResource, bool)
GetResource retrieves a parsed resource by full name
func (*ResourceCache) Invalidate ¶
func (rc *ResourceCache) Invalidate(name string)
Invalidate removes a specific resource
func (*ResourceCache) InvalidateAll ¶
func (rc *ResourceCache) InvalidateAll(predicate func(string) bool)
InvalidateAll removes all resources matching a predicate
func (*ResourceCache) Keys ¶
func (rc *ResourceCache) Keys() []string
Keys returns all keys currently in the cache
func (*ResourceCache) Len ¶
func (rc *ResourceCache) Len() int
Len returns the number of items in the cache
func (*ResourceCache) Put ¶
func (rc *ResourceCache) Put(name string, value interface{})
Put caches any value by key (generic access)
func (*ResourceCache) PutResource ¶
func (rc *ResourceCache) PutResource(name string, resource modconfig.HclResource)
PutResource caches a parsed resource
func (*ResourceCache) Stats ¶
func (rc *ResourceCache) Stats() CacheStats
Stats returns cache statistics