cache

package
v0.28.1-0...-5776918 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

internal/cache/backup.go

internal/cache/config_api.go

internal/cache/consistency.go

internal/cache/cost_optimizer.go

internal/cache/debug.go

internal/cache/geo_cache.go

internal/cache/patterns.go

internal/cache/prefetch.go

internal/cache/recovery.go

internal/cache/tiered_cache.go

internal/cache/time_strategies.go

internal/cache/user_cache.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessPattern

type AccessPattern struct {
	Count      int
	LastAccess time.Time
	Window     time.Duration
}

AccessPattern tracks access patterns for cache items

type AccessPatternAnalysis

type AccessPatternAnalysis struct {
	Key            string
	AccessCount    int64
	LastAccess     time.Time
	AccessInterval time.Duration
	Predictability float64 // 0-1 score
}

AccessPattern represents analyzed access patterns

type BackupInfo

type BackupInfo struct {
	ID           string                 `json:"id"`
	Type         BackupType             `json:"type"`
	Timestamp    time.Time              `json:"timestamp"`
	ItemCount    int                    `json:"item_count"`
	Size         int64                  `json:"size"`
	Encrypted    bool                   `json:"encrypted"`
	BaseBackupID string                 `json:"base_backup_id,omitempty"`
	Checksum     string                 `json:"checksum"`
	CacheStats   map[string]interface{} `json:"cache_stats"`
}

BackupInfo contains metadata about a backup

type BackupItem

type BackupItem struct {
	Key       string    `json:"key"`
	Size      int64     `json:"size"`
	Checksum  string    `json:"checksum"`
	Timestamp time.Time `json:"timestamp"`
	Offset    int64     `json:"offset"`
}

BackupItem represents a single item in the backup

type BackupManifest

type BackupManifest struct {
	Info    *BackupInfo  `json:"info"`
	Items   []BackupItem `json:"items"`
	Version int          `json:"version"`
}

BackupManifest contains the backup metadata and item list

type BackupSchedule

type BackupSchedule struct {
	Enabled    bool
	Interval   time.Duration
	BackupDir  string
	Type       BackupType
	MaxBackups int
	OnSuccess  func(*BackupInfo)
	OnError    func(error)
	// contains filtered or unexported fields
}

BackupSchedule defines automatic backup configuration

type BackupType

type BackupType string

BackupType defines the type of backup

const (
	BackupTypeFull        BackupType = "full"
	BackupTypeIncremental BackupType = "incremental"
)

type CacheConfig

type CacheConfig struct {

	// Size limits
	MemorySize int64 `json:"memory_size"`
	SSDSize    int64 `json:"ssd_size"`

	// Performance tuning
	CompressionEnabled bool   `json:"compression_enabled"`
	CompressionAlgo    string `json:"compression_algo"`
	EncryptionEnabled  bool   `json:"encryption_enabled"`
	DeduplicationOn    bool   `json:"deduplication_on"`

	// Eviction policy
	EvictionPolicy string        `json:"eviction_policy"`
	TTL            time.Duration `json:"ttl"`

	// Advanced features
	PrefetchEnabled  bool   `json:"prefetch_enabled"`
	ConsistencyLevel string `json:"consistency_level"`
	DebugMode        bool   `json:"debug_mode"`
}

CacheConfig represents runtime cache configuration

type CacheDebugger

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

CacheDebugger provides debugging tools for cache inspection

func NewCacheDebugger

func NewCacheDebugger(cache *SSDCache) *CacheDebugger

NewCacheDebugger creates a cache debugging tool

func (*CacheDebugger) DumpCache

func (d *CacheDebugger) DumpCache() map[string]string

DumpCache returns a snapshot of cache contents

func (*CacheDebugger) Enable

func (d *CacheDebugger) Enable()

Enable turns on debug tracing

func (*CacheDebugger) GetCacheStats

func (d *CacheDebugger) GetCacheStats() map[string]interface{}

GetCacheStats returns current cache statistics

func (*CacheDebugger) GetSlowOperations

func (d *CacheDebugger) GetSlowOperations(threshold time.Duration) []*OperationTrace

GetSlowOperations returns operations slower than threshold

func (*CacheDebugger) TraceOperation

func (d *CacheDebugger) TraceOperation(op string, key string, size int64, duration time.Duration, hit bool, err error)

TraceOperation records a cache operation

type CacheItem

type CacheItem struct {
	Container    string
	Artifact     string
	Data         []byte
	Size         int64
	LastAccessed time.Time
}

CacheItem represents a single cached artifact

type CacheManager

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

CacheManager combines all cache features

func NewCacheManager

func NewCacheManager(maxBytes int64) *CacheManager

NewCacheManager creates a fully-featured cache

func (*CacheManager) Get

func (cm *CacheManager) Get(ctx context.Context, container, artifact string) (io.Reader, bool, error)

Get with full metrics tracking

type CacheStats

type CacheStats struct {
	Items     int
	Hits      int64
	Misses    int64
	Evictions int64
	Capacity  int
}

CacheStats holds cache statistics

func (*CacheStats) HitRate

func (s *CacheStats) HitRate() float64

HitRate calculates the cache hit rate

type CacheValue

type CacheValue struct {
	Key           string
	Size          int64
	AccessCount   int64
	LastAccess    time.Time
	StorageCost   float64
	AccessSavings float64
	NetValue      float64
}

CacheValue represents the value/cost analysis of cached data

type CacheVersion

type CacheVersion struct {
	Key       string
	Version   int64
	Timestamp time.Time
	Checksum  string
	Source    string
}

CacheVersion tracks cache entry versions

type CacheWarmer

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

Step 204: Cache Warming

func (*CacheWarmer) WarmCache

func (w *CacheWarmer) WarmCache(keys []string) error

WarmCache loads frequently accessed items on startup

type ClusterNode

type ClusterNode struct {
	ID       string
	Address  string
	IsLeader bool
}

Step 208: Cache Clustering (simplified)

type ClusteredCache

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

func (*ClusteredCache) Replicate

func (c *ClusteredCache) Replicate(key string, data []byte) error

Replicate sends cache updates to other nodes

type CompressionStats

type CompressionStats struct {
	OriginalSize     int64
	CompressedSize   int64
	BytesSaved       int64
	CompressionRatio float64
}

CompressionStats tracks compression effectiveness

type Config

type Config struct {
	MemorySize int64
	SSDSize    int64
	SSDPath    string
}

type ConfigAPI

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

ConfigAPI provides runtime configuration management

func NewConfigAPI

func NewConfigAPI(cache *SSDCache) *ConfigAPI

NewConfigAPI creates a configuration API

func (*ConfigAPI) GetConfig

func (api *ConfigAPI) GetConfig() *CacheConfig

GetConfig returns current configuration

func (*ConfigAPI) RegisterChangeListener

func (api *ConfigAPI) RegisterChangeListener(callback func(*CacheConfig))

RegisterChangeListener adds a config change callback

func (*ConfigAPI) UpdateConfig

func (api *ConfigAPI) UpdateConfig(updates map[string]interface{}) error

UpdateConfig applies new configuration

func (*ConfigAPI) ValidateConfig

func (api *ConfigAPI) ValidateConfig(config *CacheConfig) []string

ValidateConfig checks if configuration is valid

type ConsistencyLevel

type ConsistencyLevel int

ConsistencyLevel defines cache consistency guarantees

const (
	EventualConsistency ConsistencyLevel = iota
	StrongConsistency
	BoundedStaleness
)

type ConsistencyManager

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

ConsistencyManager ensures cache consistency across nodes

func NewConsistencyManager

func NewConsistencyManager(level ConsistencyLevel) *ConsistencyManager

NewConsistencyManager creates a consistency controller

func (*ConsistencyManager) Invalidate

func (c *ConsistencyManager) Invalidate(key string)

Invalidate marks cache entry as invalid

func (*ConsistencyManager) UpdateVersion

func (c *ConsistencyManager) UpdateVersion(key string, version int64, checksum string)

UpdateVersion updates the version info for a key

func (*ConsistencyManager) ValidateConsistency

func (c *ConsistencyManager) ValidateConsistency(key string, localVersion int64) bool

ValidateConsistency checks if cached data is consistent

type CostOptimizer

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

CostOptimizer optimizes cache usage based on cost/benefit

func NewCostOptimizer

func NewCostOptimizer(budget float64) *CostOptimizer

NewCostOptimizer creates a cost-aware cache optimizer

func (*CostOptimizer) AnalyzeValue

func (c *CostOptimizer) AnalyzeValue(key string, size int64, accessCount int64) *CacheValue

AnalyzeValue calculates the value of caching specific data

func (*CostOptimizer) GetOptimalTier

func (c *CostOptimizer) GetOptimalTier(accessFreq float64, size int64) *StorageTier

GetOptimalTier returns the most cost-effective tier for data

func (*CostOptimizer) ShouldCache

func (c *CostOptimizer) ShouldCache(key string, size int64, predictedAccess int64) bool

ShouldCache determines if data is worth caching based on cost

type DedupBlock

type DedupBlock struct {
	Hash     string
	RefCount int
	Size     int64
	Path     string
}

DedupBlock represents a deduplicated data block

type DeduplicationStats

type DeduplicationStats struct {
	UniqueBlocks    int64
	TotalReferences int64
	SpaceSaved      int64
}

DeduplicationStats tracks deduplication effectiveness

type DemotionPolicy

type DemotionPolicy struct {
	MaxAge        time.Duration // Max time in memory without access
	LowWaterMark  int64         // Start demotion when memory usage exceeds this
	HighWaterMark int64         // Aggressively demote when exceeding this
}

DemotionPolicy defines when to demote data from memory to SSD

type EdgeNode

type EdgeNode struct {
	ID       string
	Location GeoLocation
	Capacity int64
	Load     float64
	Latency  time.Duration
	Active   bool
}

EdgeNode represents a cache edge node

type EvictionPolicy

type EvictionPolicy interface {
	SelectVictim(items map[string]*CacheItem) string
}

Step 206: Cache Eviction Policies

type FailoverStatus

type FailoverStatus string

FailoverStatus represents failover state

const (
	FailoverStatusActive   FailoverStatus = "active"
	FailoverStatusInactive FailoverStatus = "inactive"
)

type GeoCacheManager

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

GeoCacheManager manages geographically distributed caching

func NewGeoCacheManager

func NewGeoCacheManager() *GeoCacheManager

NewGeoCacheManager creates a geo-aware cache manager

func (*GeoCacheManager) AddEdgeNode

func (g *GeoCacheManager) AddEdgeNode(node *EdgeNode)

AddEdgeNode registers an edge cache node

func (*GeoCacheManager) FindNearestEdge

func (g *GeoCacheManager) FindNearestEdge(userLoc GeoLocation) *EdgeNode

FindNearestEdge finds the closest edge node to a user

type GeoLocation

type GeoLocation struct {
	Latitude  float64
	Longitude float64
	Region    string
	City      string
	Country   string
}

GeoLocation represents a geographic location

type HotDataTracker

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

Step 205: Hot Data Identification

func (*HotDataTracker) IsHot

func (h *HotDataTracker) IsHot(key string) bool

IsHot determines if data should be cached

func (*HotDataTracker) RecordAccess

func (h *HotDataTracker) RecordAccess(key string)

RecordAccess updates access tracking

type HourlyPattern

type HourlyPattern struct {
	Hour         int
	AvgRequests  float64
	AvgCacheSize int64
	HotKeys      []string
}

HourlyPattern tracks usage patterns by hour

type IntegrityReport

type IntegrityReport struct {
	TotalFiles     int      `json:"total_files"`
	CorruptedFiles int      `json:"corrupted_files"`
	CorruptedKeys  []string `json:"corrupted_keys"`
	MissingFiles   int      `json:"missing_files"`
	OrphanedFiles  int      `json:"orphaned_files"`
	SpaceReclaimed int64    `json:"space_reclaimed"`
}

IntegrityReport contains results of integrity check

type InvalidationAPI

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

Step 209: Cache Invalidation API

func (*InvalidationAPI) InvalidateAll

func (api *InvalidationAPI) InvalidateAll() error

InvalidateAll clears entire cache

func (*InvalidationAPI) InvalidateKey

func (api *InvalidationAPI) InvalidateKey(container, artifact string) error

InvalidateKey removes a specific key

func (*InvalidationAPI) InvalidatePattern

func (api *InvalidationAPI) InvalidatePattern(pattern string) error

InvalidatePattern removes keys matching pattern

type JournalOperation

type JournalOperation struct {
	Type      string    `json:"type"`
	Key       string    `json:"key"`
	DataPath  string    `json:"data_path,omitempty"`
	Timestamp time.Time `json:"timestamp"`
}

JournalOperation represents a pending cache operation

type LFUPolicy

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

func (*LFUPolicy) SelectVictim

func (p *LFUPolicy) SelectVictim(items map[string]*CacheItem) string

type LRU

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

LRU implements a Least Recently Used cache

func NewLRU

func NewLRU(capacity int) *LRU

NewLRU creates a new LRU cache with the given capacity

func (*LRU) Clear

func (c *LRU) Clear()

Clear removes all items from the cache

func (*LRU) Delete

func (c *LRU) Delete(ctx context.Context, container, artifact string) error

Delete removes an item from the cache

func (*LRU) Get

func (c *LRU) Get(ctx context.Context, container, artifact string) (io.Reader, bool, error)

Get retrieves an item from the cache

func (*LRU) Put

func (c *LRU) Put(ctx context.Context, container, artifact string, reader io.Reader, size int64) error

Put adds an item to the cache

func (*LRU) Stats

func (c *LRU) Stats() *CacheStats

Stats returns current cache statistics

type LRUPolicy

type LRUPolicy struct{}

func (*LRUPolicy) SelectVictim

func (p *LRUPolicy) SelectVictim(items map[string]*CacheItem) string

type MetricsTracker

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

MetricsTracker tracks detailed cache metrics

func NewMetricsTracker

func NewMetricsTracker() *MetricsTracker

NewMetricsTracker creates a new metrics tracker

func (*MetricsTracker) GetHitRate

func (m *MetricsTracker) GetHitRate() float64

GetHitRate returns overall hit rate

func (*MetricsTracker) GetTopKeys

func (m *MetricsTracker) GetTopKeys(n int) []string

GetTopKeys returns the most accessed keys

func (*MetricsTracker) RecordHit

func (m *MetricsTracker) RecordHit(key string, latency time.Duration, bytes int64)

RecordHit records a cache hit

func (*MetricsTracker) RecordMiss

func (m *MetricsTracker) RecordMiss(key string, latency time.Duration)

RecordMiss records a cache miss

func (*MetricsTracker) RecordPut

func (m *MetricsTracker) RecordPut(key string, latency time.Duration, bytes int64)

RecordPut records a cache put operation

type OperationTrace

type OperationTrace struct {
	Timestamp  time.Time
	Operation  string
	Key        string
	Size       int64
	Duration   time.Duration
	Hit        bool
	Error      error
	StackTrace string
}

OperationTrace records cache operation details

type PatternAnalyzer

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

PatternAnalyzer tracks and analyzes access patterns

func NewPatternAnalyzer

func NewPatternAnalyzer(window time.Duration) *PatternAnalyzer

NewPatternAnalyzer creates a pattern analyzer

func (*PatternAnalyzer) GetHotKeys

func (p *PatternAnalyzer) GetHotKeys(limit int) []string

GetHotKeys returns the most frequently accessed keys

func (*PatternAnalyzer) GetPattern

func (p *PatternAnalyzer) GetPattern(key string) *AccessPatternAnalysis

GetPattern returns the access pattern for a key

func (*PatternAnalyzer) TrackAccess

func (p *PatternAnalyzer) TrackAccess(key string)

TrackAccess records an access to a key

type PerformanceMetrics

type PerformanceMetrics struct {
	// Latency tracking
	PutLatencyP50 time.Duration
	GetLatencyP50 time.Duration

	// Operation counts
	PutCount int64
	GetCount int64

	// Hit rate tracking
	CacheHits   int64
	CacheMisses int64
	HitRate     float64
}

PerformanceMetrics tracks cache performance

type PerformanceMonitor

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

Step 210: Cache Performance Metrics

func (*PerformanceMonitor) GetP99Latency

func (pm *PerformanceMonitor) GetP99Latency() time.Duration

GetP99Latency returns 99th percentile latency

func (*PerformanceMonitor) RecordGet

func (pm *PerformanceMonitor) RecordGet(latency time.Duration, bytes int64)

RecordGet tracks get operation performance

type PersistentCache

type PersistentCache struct {
	*SizedLRU
	// contains filtered or unexported fields
}

Step 207: Cache Persistence

func (*PersistentCache) LoadFromDisk

func (p *PersistentCache) LoadFromDisk() error

LoadFromDisk restores cache from disk

func (*PersistentCache) SaveToDisk

func (p *PersistentCache) SaveToDisk() error

SaveToDisk persists cache to disk

type PredictivePrefetcher

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

PredictivePrefetcher handles intelligent prefetching

func NewPredictivePrefetcher

func NewPredictivePrefetcher(analyzer *PatternAnalyzer, strategy PrefetchStrategy) *PredictivePrefetcher

NewPredictivePrefetcher creates a new prefetcher

func (*PredictivePrefetcher) TriggerPrefetch

func (p *PredictivePrefetcher) TriggerPrefetch(key string)

TriggerPrefetch analyzes if prefetch should occur

type PrefetchStrategy

type PrefetchStrategy interface {
	ShouldPrefetch(key string, pattern *AccessPatternAnalysis) bool
	GetPrefetchKeys(key string) []string
}

PrefetchStrategy defines how to predict and prefetch data

type PromotionPolicy

type PromotionPolicy struct {
	FrequencyThreshold int           // Min accesses to trigger promotion
	TimeWindow         time.Duration // Time window for counting accesses
	SizeLimit          int64         // Max size to promote (avoid huge files in memory)
}

PromotionPolicy defines when to promote data from SSD to memory

type RecoveryJournal

type RecoveryJournal struct {
	Timestamp  time.Time          `json:"timestamp"`
	Operations []JournalOperation `json:"operations"`
}

RecoveryJournal tracks pending operations for crash recovery

type RecoveryReport

type RecoveryReport struct {
	Status         RecoveryStatus `json:"status"`
	RecoveredItems int            `json:"recovered_items"`
	FailedItems    int            `json:"failed_items"`
	Duration       time.Duration  `json:"duration"`
	Errors         []string       `json:"errors"`
}

RecoveryReport contains recovery operation results

type RecoveryStatus

type RecoveryStatus string

RecoveryStatus represents the status of a recovery operation

const (
	RecoveryStatusSuccess RecoveryStatus = "success"
	RecoveryStatusPartial RecoveryStatus = "partial"
	RecoveryStatusFailed  RecoveryStatus = "failed"
)

type ReplicationConfig

type ReplicationConfig struct {
	Mode          ReplicationMode
	SecondaryPath string
	SyncInterval  time.Duration
	// contains filtered or unexported fields
}

ReplicationConfig defines replication settings

type ReplicationMode

type ReplicationMode string

ReplicationMode defines how replication works

const (
	ReplicationModeAsync ReplicationMode = "async"
	ReplicationModeSync  ReplicationMode = "sync"
)

type SSDCache

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

SSDCache implements a tiered cache with memory and SSD storage

func NewSSDCache

func NewSSDCache(memSize, ssdSize int64, ssdPath string) (*SSDCache, error)

NewSSDCache creates a new SSD-backed cache

func NewSSDCacheWithReplication

func NewSSDCacheWithReplication(memSize, ssdSize int64, primaryPath string, config *ReplicationConfig) (*SSDCache, error)

NewSSDCacheWithReplication creates a cache with replication

func RecoverFromDisaster

func RecoverFromDisaster(cacheDir, backupDir, backupID string) (*SSDCache, error)

RecoverFromDisaster creates a new cache from backup

func (*SSDCache) ApplyDemotionPolicy

func (c *SSDCache) ApplyDemotionPolicy()

ApplyDemotionPolicy actively demotes old items based on policy

func (*SSDCache) CheckIntegrity

func (c *SSDCache) CheckIntegrity() (*IntegrityReport, error)

CheckIntegrity verifies cache data integrity

func (*SSDCache) CleanOrphanedFiles

func (c *SSDCache) CleanOrphanedFiles() (*IntegrityReport, error)

CleanOrphanedFiles removes files without index entries

func (*SSDCache) CreateBackup

func (c *SSDCache) CreateBackup(backupDir string, backupType BackupType) (*BackupInfo, error)

CreateBackup creates a full backup of the cache

func (*SSDCache) CreateEncryptedBackup

func (c *SSDCache) CreateEncryptedBackup(backupDir string, backupType BackupType, encryptionKey []byte) (*BackupInfo, error)

CreateEncryptedBackup creates an encrypted backup

func (*SSDCache) CreateIncrementalBackup

func (c *SSDCache) CreateIncrementalBackup(backupDir string, baseBackupID string) (*BackupInfo, error)

CreateIncrementalBackup creates an incremental backup since the last full backup

func (*SSDCache) Delete

func (c *SSDCache) Delete(key string) error

Delete removes an item from cache

func (*SSDCache) EnableCompression

func (c *SSDCache) EnableCompression(algorithm string)

EnableCompression turns on data compression for SSD storage

func (*SSDCache) EnableDeduplication

func (c *SSDCache) EnableDeduplication()

EnableDeduplication turns on content deduplication

func (*SSDCache) EnableEncryption

func (c *SSDCache) EnableEncryption(key []byte) error

EnableEncryption enables AES-256-GCM encryption for data at rest

func (*SSDCache) EnableMonitoring

func (c *SSDCache) EnableMonitoring()

EnableMonitoring turns on performance tracking

func (*SSDCache) ExportToJSON

func (c *SSDCache) ExportToJSON(path string) error

ExportToJSON exports cache contents to JSON

func (*SSDCache) Get

func (c *SSDCache) Get(key string) ([]byte, bool)

Get retrieves from memory or SSD

func (*SSDCache) GetCompressionStats

func (c *SSDCache) GetCompressionStats() *CompressionStats

GetCompressionStats returns compression statistics

func (*SSDCache) GetDeduplicationStats

func (c *SSDCache) GetDeduplicationStats() *DeduplicationStats

GetDeduplicationStats returns deduplication statistics

func (*SSDCache) GetFailoverStatus

func (c *SSDCache) GetFailoverStatus() FailoverStatus

GetFailoverStatus returns current failover status

func (*SSDCache) GetLastRecoveryReport

func (c *SSDCache) GetLastRecoveryReport() *RecoveryReport

GetLastRecoveryReport returns the last recovery report

func (*SSDCache) GetMemoryKeys

func (c *SSDCache) GetMemoryKeys() []string

GetMemoryKeys returns keys currently in memory (for testing)

func (*SSDCache) GetPerformanceMetrics

func (c *SSDCache) GetPerformanceMetrics() *PerformanceMetrics

GetPerformanceMetrics returns current performance stats

func (*SSDCache) GetShardForKey

func (c *SSDCache) GetShardForKey(key string) int

GetShardForKey returns the shard number for a given key

func (*SSDCache) GetWriteStats

func (c *SSDCache) GetWriteStats() map[string]interface{}

GetWriteStats returns wear leveling statistics

func (*SSDCache) ImportFromJSON

func (c *SSDCache) ImportFromJSON(path string) (int, error)

ImportFromJSON imports cache contents from JSON

func (*SSDCache) IsHot

func (c *SSDCache) IsHot(key string) bool

IsHot returns true if the key has been accessed frequently

func (*SSDCache) IsUsingSecondary

func (c *SSDCache) IsUsingSecondary() bool

IsUsingSecondary returns true if using secondary cache

func (*SSDCache) Put

func (c *SSDCache) Put(key string, data []byte) error

Put stores in memory and potentially demotes to SSD

func (*SSDCache) RecoverIndex

func (c *SSDCache) RecoverIndex() (int, error)

RecoverIndex rebuilds the index from disk files

func (*SSDCache) RepairCorruption

func (c *SSDCache) RepairCorruption(report *IntegrityReport) (int, error)

RepairCorruption attempts to fix corrupted entries

func (*SSDCache) RestoreFromBackup

func (c *SSDCache) RestoreFromBackup(backupDir string, backupID string) error

RestoreFromBackup restores cache from a backup

func (*SSDCache) RotateEncryptionKey

func (c *SSDCache) RotateEncryptionKey(newKey []byte) error

RotateEncryptionKey changes the encryption key for new data

func (*SSDCache) SetDemotionPolicy

func (c *SSDCache) SetDemotionPolicy(policy *DemotionPolicy)

SetDemotionPolicy configures when data moves from memory to SSD

func (*SSDCache) SetPromotionPolicy

func (c *SSDCache) SetPromotionPolicy(policy *PromotionPolicy)

SetPromotionPolicy configures when data moves from SSD to memory

func (*SSDCache) SimulateFailure

func (c *SSDCache) SimulateFailure()

SimulateFailure simulates a primary cache failure for testing

func (*SSDCache) StartBackupScheduler

func (c *SSDCache) StartBackupScheduler(schedule *BackupSchedule) error

StartBackupScheduler starts automatic backups

func (*SSDCache) Stats

func (c *SSDCache) Stats() map[string]interface{}

Stats returns cache statistics

func (*SSDCache) StopBackupScheduler

func (c *SSDCache) StopBackupScheduler()

StopBackupScheduler stops automatic backups

func (*SSDCache) ValidateBackup

func (c *SSDCache) ValidateBackup(backupDir string, backupID string) (bool, error)

ValidateBackup checks backup integrity

type SSDEntry

type SSDEntry struct {
	Key        string
	Size       int64
	Path       string
	AccessTime time.Time
}

SSDEntry represents an item stored on SSD

type SequentialPrefetchStrategy

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

SequentialPrefetchStrategy prefetches sequential keys

func (*SequentialPrefetchStrategy) GetPrefetchKeys

func (s *SequentialPrefetchStrategy) GetPrefetchKeys(key string) []string

func (*SequentialPrefetchStrategy) ShouldPrefetch

func (s *SequentialPrefetchStrategy) ShouldPrefetch(key string, pattern *AccessPatternAnalysis) bool

type SizedCacheItem

type SizedCacheItem struct {
	CacheItem
	ByteSize int64
}

SizedCacheItem includes size tracking

type SizedCacheStats

type SizedCacheStats struct {
	CacheStats
	CurrentBytes int64
	MaxBytes     int64
	BytesEvicted int64
}

SizedCacheStats includes byte size information

func (*SizedCacheStats) MemoryUsage

func (s *SizedCacheStats) MemoryUsage() float64

MemoryUsage returns current memory usage percentage

type SizedLRU

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

SizedLRU implements an LRU cache with byte size limits

func NewSizedLRU

func NewSizedLRU(maxBytes int64) *SizedLRU

NewSizedLRU creates a cache with byte size limit

func (*SizedLRU) Delete

func (c *SizedLRU) Delete(ctx context.Context, container, artifact string) error

Delete removes an item from the cache

func (*SizedLRU) Get

func (c *SizedLRU) Get(ctx context.Context, container, artifact string) (io.Reader, bool, error)

Get retrieves an item from the cache

func (*SizedLRU) Put

func (c *SizedLRU) Put(ctx context.Context, container, artifact string, reader io.Reader, size int64) error

Put adds an item to the cache with size tracking

func (*SizedLRU) Stats

func (c *SizedLRU) Stats() *SizedCacheStats

Stats returns current cache statistics

type StorageTier

type StorageTier struct {
	Name         string
	CostPerGB    float64 // $ per GB per month
	AccessCost   float64 // $ per 1000 requests
	Latency      time.Duration
	Capacity     int64
	CurrentUsage int64
}

StorageTier represents different storage cost tiers

type TieredCache

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

func NewTieredCache

func NewTieredCache(config *Config, logger *zap.Logger) *TieredCache

func (*TieredCache) Delete

func (tc *TieredCache) Delete(key string) error

func (*TieredCache) Flush

func (tc *TieredCache) Flush()

func (*TieredCache) Get

func (tc *TieredCache) Get(key string) ([]byte, error)

func (*TieredCache) GetMetrics

func (tc *TieredCache) GetMetrics() map[string]interface{}

func (*TieredCache) HealthCheck

func (tc *TieredCache) HealthCheck() error

func (*TieredCache) Set

func (tc *TieredCache) Set(key string, data []byte) error

type TimeBasedStrategy

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

TimeBasedStrategy handles time-aware caching decisions

func NewTimeBasedStrategy

func NewTimeBasedStrategy() *TimeBasedStrategy

NewTimeBasedStrategy creates a time-aware strategy

func (*TimeBasedStrategy) GetOptimalTTL

func (t *TimeBasedStrategy) GetOptimalTTL(key string, baselineTTL time.Duration) time.Duration

GetOptimalTTL returns TTL based on time of day

func (*TimeBasedStrategy) RecordHourlyPattern

func (t *TimeBasedStrategy) RecordHourlyPattern(requests int, cacheSize int64, hotKeys []string)

RecordHourlyPattern records usage for the current hour

type UserAwareCacheManager

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

UserAwareCacheManager manages user-specific caching

func NewUserAwareCacheManager

func NewUserAwareCacheManager(cache *SSDCache, maxPerUser int64) *UserAwareCacheManager

NewUserAwareCacheManager creates a user-aware cache manager

func (*UserAwareCacheManager) GetUserProfile

func (u *UserAwareCacheManager) GetUserProfile(userID string) *UserCacheProfile

GetUserProfile returns or creates a user's cache profile

func (*UserAwareCacheManager) ShouldCacheForUser

func (u *UserAwareCacheManager) ShouldCacheForUser(userID string, size int64) bool

ShouldCacheForUser determines if data should be cached for this user

func (*UserAwareCacheManager) TrackUserAccess

func (u *UserAwareCacheManager) TrackUserAccess(userID, key string, size int64)

TrackUserAccess records a user's data access

type UserCacheProfile

type UserCacheProfile struct {
	UserID          string
	HotKeys         []string
	AvgObjectSize   int64
	TotalSize       int64 // Track total size for proper averaging
	AccessCount     int64 // Track access count for proper averaging
	AccessFrequency float64
	LastAccess      time.Time
	CacheQuota      int64 // Bytes allocated to this user
	CurrentUsage    int64
}

UserCacheProfile tracks per-user cache behavior

Jump to

Keyboard shortcuts

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