Documentation
¶
Index ¶
- func CacheKey(components ...string) string
- func CacheResult[T any](cache *Cache[T], key string, ttl time.Duration, fn func() (T, error)) (T, error)
- func InitCaches()
- func InvalidateByType(cacheType CacheType)
- func InvalidateCacheForCommand(command string)
- func InvalidateCommandCache()
- func InvalidateHelmCache()
- func InvalidateIstioCache()
- func InvalidateKubernetesCache()
- type Cache
- func (c *Cache[T]) Clear()
- func (c *Cache[T]) Close()
- func (c *Cache[T]) Delete(key string)
- func (c *Cache[T]) Get(key string) (T, bool)
- func (c *Cache[T]) Name() string
- func (c *Cache[T]) Set(key string, value T)
- func (c *Cache[T]) SetWithTTL(key string, value T, ttl time.Duration)
- func (c *Cache[T]) Size() int
- func (c *Cache[T]) Stats() CacheStats
- type CacheEntry
- type CacheStats
- type CacheType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CacheResult ¶
func CacheResult[T any](cache *Cache[T], key string, ttl time.Duration, fn func() (T, error)) (T, error)
CacheResult is a helper function to cache the result of a function
func InvalidateByType ¶
func InvalidateByType(cacheType CacheType)
InvalidateByType clears the entire cache for a specific cache type
func InvalidateCacheForCommand ¶
func InvalidateCacheForCommand(command string)
InvalidateCacheForCommand invalidates the appropriate cache based on command type
func InvalidateCommandCache ¶
func InvalidateCommandCache()
InvalidateCommandCache clears the Command cache
func InvalidateKubernetesCache ¶
func InvalidateKubernetesCache()
InvalidateKubernetesCache clears the Kubernetes cache
Types ¶
type Cache ¶
type Cache[T any] struct { // contains filtered or unexported fields }
Cache is a thread-safe cache with TTL support
func GetCacheByCommand ¶
GetCacheByCommand returns a cache instance based on the command name
func GetCacheByType ¶
GetCacheByType returns a cache instance by cache type
func NewCache ¶
func NewCache[T any](name string, defaultTTL time.Duration, maxSize int, cleanupInterval time.Duration) *Cache[T]
NewCache creates a new cache with specified configuration and name
func (*Cache[T]) SetWithTTL ¶
SetWithTTL stores a value in the cache with specified TTL
type CacheEntry ¶
type CacheEntry[T any] struct { Value T CreatedAt time.Time ExpiresAt time.Time AccessedAt time.Time AccessCount int64 }
CacheEntry represents a cached item with TTL
func (*CacheEntry[T]) IsExpired ¶
func (e *CacheEntry[T]) IsExpired() bool
IsExpired checks if the cache entry has expired
type CacheStats ¶
type CacheStats struct {
Size int `json:"size"`
MaxSize int `json:"max_size"`
Expired int `json:"expired"`
Oldest time.Time `json:"oldest"`
Newest time.Time `json:"newest"`
}
CacheStats represents cache statistics