cache

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheKey

func CacheKey(components ...string) string

CacheKey generates a consistent cache key from components

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 InitCaches

func InitCaches()

InitCaches initializes all global cache instances

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 InvalidateHelmCache

func InvalidateHelmCache()

InvalidateHelmCache clears the Helm cache

func InvalidateIstioCache

func InvalidateIstioCache()

InvalidateIstioCache clears the Istio 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

func GetCacheByCommand(command string) *Cache[string]

GetCacheByCommand returns a cache instance based on the command name

func GetCacheByType

func GetCacheByType(cacheType CacheType) *Cache[string]

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]) Clear

func (c *Cache[T]) Clear()

Clear removes all items from the cache

func (*Cache[T]) Close

func (c *Cache[T]) Close()

Close stops the cache cleanup goroutine

func (*Cache[T]) Delete

func (c *Cache[T]) Delete(key string)

Delete removes a value from the cache

func (*Cache[T]) Get

func (c *Cache[T]) Get(key string) (T, bool)

Get retrieves a value from the cache

func (*Cache[T]) Name

func (c *Cache[T]) Name() string

Name returns the name of the cache

func (*Cache[T]) Set

func (c *Cache[T]) Set(key string, value T)

Set stores a value in the cache with default TTL

func (*Cache[T]) SetWithTTL

func (c *Cache[T]) SetWithTTL(key string, value T, ttl time.Duration)

SetWithTTL stores a value in the cache with specified TTL

func (*Cache[T]) Size

func (c *Cache[T]) Size() int

Size returns the current number of items in the cache

func (*Cache[T]) Stats

func (c *Cache[T]) Stats() CacheStats

Stats returns cache statistics

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

type CacheType

type CacheType int

CacheType represents the type of cache using enum pattern

const (
	CacheTypeKubernetes CacheType = iota
	CacheTypeCommand
	CacheTypeHelm
	CacheTypeIstio
)

func (CacheType) String

func (ct CacheType) String() string

String returns the string representation of CacheType

Jump to

Keyboard shortcuts

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