cache

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

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 an in-memory cache with TTL and LRU eviction

func NewCache

func NewCache(maxSize int, ttl time.Duration) *Cache

NewCache creates a new cache with the specified configuration

func NewCacheWithEvictionCallback

func NewCacheWithEvictionCallback(maxSize int, ttl time.Duration, callback EvictionCallback) *Cache

NewCacheWithEvictionCallback creates a new cache with eviction callback

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes all items from the cache

func (*Cache) Close

func (c *Cache) Close()

Close stops the cleanup goroutine

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete removes a feature flag from the cache

func (*Cache) Get

func (c *Cache) Get(key string) (*core.FeatureFlag, bool)

Get retrieves a feature flag from the cache Optimized for read-heavy workloads with minimal lock contention

func (*Cache) Set

func (c *Cache) Set(key string, flag *core.FeatureFlag)

Set stores a feature flag in the cache

func (*Cache) Size

func (c *Cache) Size() int

Size returns the current number of items in the cache

type CachedStore

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

CachedStore wraps any Store implementation with an in-memory cache

func NewStore

func NewStore(store core.Store, cacheConfig config.CacheConfig) *CachedStore

NewCachedStore creates a new cached store wrapper

func NewStoreWithMetrics

func NewStoreWithMetrics(store core.Store, cacheConfig config.CacheConfig, metrics observability.MetricsCollector) *CachedStore

NewCachedStoreWithMetrics creates a new cached store wrapper with metrics

func (*CachedStore) Close

func (cs *CachedStore) Close() error

Close cleanly shuts down both cache and store

func (*CachedStore) Delete

func (cs *CachedStore) Delete(ctx context.Context, key string) error

Delete removes a feature flag from both cache and store

func (*CachedStore) Get

func (cs *CachedStore) Get(ctx context.Context, key string) (*core.FeatureFlag, error)

Get retrieves a feature flag, checking cache first

func (*CachedStore) GetAll

func (cs *CachedStore) GetAll(ctx context.Context) ([]core.FeatureFlag, error)

GetAll retrieves all feature flags from the underlying store Note: This bypasses cache for consistency and performance reasons

func (*CachedStore) HealthCheck

func (cs *CachedStore) HealthCheck(ctx context.Context) error

HealthCheck verifies connectivity of the underlying store

func (*CachedStore) Set

func (cs *CachedStore) Set(ctx context.Context, flag core.FeatureFlag) error

Set creates or updates a feature flag in both cache and store

type EvictionCallback

type EvictionCallback func(key string, flag *core.FeatureFlag)

EvictionCallback is called when an item is evicted from the cache

Jump to

Keyboard shortcuts

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