Documentation
¶
Index ¶
- type Cache
- type CacheType
- type InvalidationAction
- type InvalidationCondition
- type InvalidationPattern
- type Manager
- func (m *Manager) AddInvalidationPattern(pattern InvalidationPattern)
- func (m *Manager) Close() error
- func (m *Manager) Delete(key string)
- func (m *Manager) Get(key string) (interface{}, bool)
- func (m *Manager) GetMetrics() *Metrics
- func (m *Manager) Prefetch(req PrefetchRequest)
- func (m *Manager) Set(key string, value interface{}, ttl time.Duration)
- type ManagerOptions
- type Metrics
- type Options
- type PrefetchRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
// Get retrieves a value from the cache
Get(key string) (interface{}, bool)
// Set adds a value to the cache with the given TTL
Set(key string, value interface{}, ttl time.Duration)
// Delete removes a value from the cache
Delete(key string)
// Clear removes all items from the cache
Clear()
// Prefetch queues a key for background prefetching
Prefetch(key string)
// Close closes the cache
Close() error
// GetMetrics returns cache metrics
GetMetrics() *Metrics
}
Cache is the interface for cache implementations
func NewBadgerCache ¶
NewBadgerCache creates a new BadgerDB-backed cache
func NewBoltCache ¶
NewBoltCache creates a new BoltDB-backed cache
func NewMemoryCache ¶
NewMemoryCache creates a new in-memory cache
type CacheType ¶
type CacheType string
CacheType represents the type of cache
const ( // MemoryCacheType is an in-memory cache MemoryCacheType CacheType = "memory" // BadgerCacheType is a BadgerDB-backed cache BadgerCacheType CacheType = "badger" // BoltCacheType is a BoltDB-backed cache BoltCacheType CacheType = "bolt" // NullCacheType is a no-op cache NullCacheType CacheType = "null" )
type InvalidationAction ¶
type InvalidationAction string
InvalidationAction is the action to take when invalidating cache items
const ( // InvalidateDelete deletes matching items InvalidateDelete InvalidationAction = "delete" // InvalidateRefresh refreshes matching items InvalidateRefresh InvalidationAction = "refresh" // InvalidateExpire expires matching items InvalidateExpire InvalidationAction = "expire" )
type InvalidationCondition ¶
type InvalidationCondition string
InvalidationCondition is the condition for invalidation
const ( // OnWrite invalidates on write operations OnWrite InvalidationCondition = "write" // OnRead invalidates on read operations OnRead InvalidationCondition = "read" // OnTime invalidates based on time OnTime InvalidationCondition = "time" )
type InvalidationPattern ¶
type InvalidationPattern struct {
// Pattern is the pattern to match cache keys
Pattern string
// Action is the action to take when the pattern matches
Action InvalidationAction
// Condition is the condition for invalidation
Condition InvalidationCondition
}
InvalidationPattern represents a pattern for cache invalidation
type Manager ¶
type Manager struct {
// Cache is the underlying cache implementation
Cache Cache
// Options are the cache manager options
Options *ManagerOptions
// contains filtered or unexported fields
}
Manager manages the cache with advanced features
func NewManager ¶
func NewManager(cache Cache, opts *ManagerOptions) *Manager
NewManager creates a new cache manager
func (*Manager) AddInvalidationPattern ¶
func (m *Manager) AddInvalidationPattern(pattern InvalidationPattern)
AddInvalidationPattern adds an invalidation pattern
func (*Manager) GetMetrics ¶
GetMetrics returns cache metrics
func (*Manager) Prefetch ¶
func (m *Manager) Prefetch(req PrefetchRequest)
Prefetch queues a key for background prefetching
type ManagerOptions ¶
type ManagerOptions struct {
// PrefetchConcurrency is the number of concurrent prefetch operations
PrefetchConcurrency int
// PrefetchQueueSize is the size of the prefetch queue
PrefetchQueueSize int
// EnablePrefetching enables background prefetching
EnablePrefetching bool
// EnableInvalidation enables cache invalidation
EnableInvalidation bool
// DefaultTTL is the default time-to-live for cached items
DefaultTTL time.Duration
// RefreshBeforeExpiry is the duration before expiry to refresh items
RefreshBeforeExpiry time.Duration
// RefreshCallback is called to refresh a cached item
RefreshCallback func(ctx context.Context, key string) (interface{}, error)
}
ManagerOptions configures the cache manager
func DefaultManagerOptions ¶
func DefaultManagerOptions() *ManagerOptions
DefaultManagerOptions returns the default manager options
type Metrics ¶
type Metrics struct {
// Gets is the number of Get operations
Gets int64
// Sets is the number of Set operations
Sets int64
// Hits is the number of cache hits
Hits int64
// Misses is the number of cache misses
Misses int64
// Deletes is the number of Delete operations
Deletes int64
// Clears is the number of Clear operations
Clears int64
// Errors is the number of errors
Errors int64
// Prefetches is the number of prefetch requests
Prefetches int64
// PrefetchesProcessed is the number of processed prefetch requests
PrefetchesProcessed int64
// Size is the current size of the cache in bytes
Size int64
// contains filtered or unexported fields
}
Metrics tracks cache performance metrics
type Options ¶
type Options struct {
// CacheDir is the directory to store cached data
CacheDir string
// DefaultTTL is the default time-to-live for cached items
DefaultTTL time.Duration
// MaxSize is the maximum size of the cache in bytes (0 = unlimited)
MaxSize int64
// MemoryLimit is the maximum memory usage in bytes (0 = unlimited)
MemoryLimit int64
// ReadOnly opens the cache in read-only mode
ReadOnly bool
// EnablePrefetching enables background prefetching
EnablePrefetching bool
// PrefetchConcurrency is the number of concurrent prefetch operations
PrefetchConcurrency int
// EnableCompression enables compression for cached values
EnableCompression bool
// EnableEncryption enables encryption for cached values
EnableEncryption bool
// EncryptionKey is the key used for encryption
EncryptionKey []byte
// EnableMetrics enables collection of cache metrics
EnableMetrics bool
}
Options configures the cache behavior
func DefaultOptions ¶
func DefaultOptions() *Options
DefaultOptions returns the default cache options
type PrefetchRequest ¶
type PrefetchRequest struct {
// Key is the cache key
Key string
// Priority is the priority of the request (higher = more important)
Priority int
// Callback is called to fetch the item if not in cache
Callback func(ctx context.Context) (interface{}, error)
}
PrefetchRequest represents a request to prefetch a cache item