Documentation
¶
Index ¶
- type AnalyticsMetrics
- type CacheAnalytics
- func (ca *CacheAnalytics) ExportMetrics(format string) ([]byte, error)
- func (ca *CacheAnalytics) GenerateInsights() []CacheInsight
- func (ca *CacheAnalytics) GetDailyStats() map[string]map[string]interface{}
- func (ca *CacheAnalytics) GetHourlyStats() map[int]map[string]interface{}
- func (ca *CacheAnalytics) GetMetrics() *AnalyticsMetrics
- func (ca *CacheAnalytics) GetPerformanceReport() map[string]interface{}
- func (ca *CacheAnalytics) GetSlowQueries(limit int) []QueryStats
- func (ca *CacheAnalytics) GetTopQueries(limit int) []QueryStats
- func (ca *CacheAnalytics) RecordCacheDelete()
- func (ca *CacheAnalytics) RecordCacheSet()
- func (ca *CacheAnalytics) RecordInvalidation()
- func (ca *CacheAnalytics) RecordRequest(query string, variables map[string]interface{}, hit bool, ...)
- func (ca *CacheAnalytics) ResetMetrics()
- type CacheInsight
- type CacheMetrics
- type CacheWarmQuery
- type CacheWarmer
- func (cw *CacheWarmer) AddWarmupQuery(query CacheWarmQuery)
- func (cw *CacheWarmer) CreateDefaultWarmupQueries()
- func (cw *CacheWarmer) GetWarmupQueries() []CacheWarmQuery
- func (cw *CacheWarmer) GetWarmupStats() map[string]interface{}
- func (cw *CacheWarmer) IsRunning() bool
- func (cw *CacheWarmer) RemoveWarmupQuery(query string)
- func (cw *CacheWarmer) Start(ctx context.Context, config *WarmupConfig) error
- func (cw *CacheWarmer) Stop()
- func (cw *CacheWarmer) WarmupNow(ctx context.Context, config *WarmupConfig) error
- type CachedQueryResult
- type ConditionOperator
- type ConditionType
- type InsightType
- type InvalidationCondition
- type InvalidationEvent
- type InvalidationManager
- func (im *InvalidationManager) AddRule(rule *InvalidationRule) error
- func (im *InvalidationManager) CreateDefaultRules() error
- func (im *InvalidationManager) ProcessEvent(ctx context.Context, event *InvalidationEvent) error
- func (im *InvalidationManager) RegisterStrategy(name string, strategy InvalidationStrategy)
- func (im *InvalidationManager) RemoveRule(ruleID string) error
- type InvalidationRule
- type InvalidationStrategy
- type QueryCache
- func (qc *QueryCache) Clear(ctx context.Context) error
- func (qc *QueryCache) Delete(ctx context.Context, query string, variables map[string]interface{}) error
- func (qc *QueryCache) Get(ctx context.Context, query string, variables map[string]interface{}) (*CachedQueryResult, bool)
- func (qc *QueryCache) GetCacheStats() map[string]interface{}
- func (qc *QueryCache) GetMetrics() *CacheMetrics
- func (qc *QueryCache) InvalidateByPattern(ctx context.Context, pattern string) error
- func (qc *QueryCache) InvalidateByTags(ctx context.Context, tags []string) error
- func (qc *QueryCache) PublishInvalidation(pattern string)
- func (qc *QueryCache) ResetMetrics()
- func (qc *QueryCache) Set(ctx context.Context, query string, variables map[string]interface{}, ...) error
- func (qc *QueryCache) SubscribeToInvalidation(pattern string) <-chan string
- func (qc *QueryCache) UnsubscribeFromInvalidation(pattern string, ch <-chan string)
- func (qc *QueryCache) WarmCache(ctx context.Context, queries []CacheWarmQuery) error
- type QueryCacheConfig
- type QueryStats
- type Severity
- type WarmupConfig
- type WarmupStrategy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnalyticsMetrics ¶
type AnalyticsMetrics struct { // Basic metrics TotalRequests int64 `json:"totalRequests"` CacheHits int64 `json:"cacheHits"` CacheMisses int64 `json:"cacheMisses"` CacheSets int64 `json:"cacheSets"` CacheDeletes int64 `json:"cacheDeletes"` CacheInvalidations int64 `json:"cacheInvalidations"` // Performance metrics AverageResponseTime time.Duration `json:"averageResponseTime"` MinResponseTime time.Duration `json:"minResponseTime"` MaxResponseTime time.Duration `json:"maxResponseTime"` TotalResponseTime time.Duration `json:"totalResponseTime"` // Hit rate metrics HitRate float64 `json:"hitRate"` HitRateByHour map[int]float64 `json:"hitRateByHour"` HitRateByDay map[string]float64 `json:"hitRateByDay"` // Query patterns TopQueries []QueryStats `json:"topQueries"` SlowQueries []QueryStats `json:"slowQueries"` QueryPatterns map[string]int `json:"queryPatterns"` // Cache efficiency CacheSize int `json:"cacheSize"` CacheUtilization float64 `json:"cacheUtilization"` MemoryUsage int64 `json:"memoryUsage"` // Time-based metrics LastReset time.Time `json:"lastReset"` LastUpdate time.Time `json:"lastUpdate"` Uptime time.Duration `json:"uptime"` }
AnalyticsMetrics holds comprehensive cache analytics
type CacheAnalytics ¶
type CacheAnalytics struct {
// contains filtered or unexported fields
}
CacheAnalytics provides analytics and insights for the GraphQL cache
func NewCacheAnalytics ¶
func NewCacheAnalytics(queryCache *QueryCache, logger *slog.Logger) *CacheAnalytics
NewCacheAnalytics creates a new cache analytics instance
func (*CacheAnalytics) ExportMetrics ¶
func (ca *CacheAnalytics) ExportMetrics(format string) ([]byte, error)
ExportMetrics exports metrics in various formats
func (*CacheAnalytics) GenerateInsights ¶
func (ca *CacheAnalytics) GenerateInsights() []CacheInsight
GenerateInsights generates insights about cache performance
func (*CacheAnalytics) GetDailyStats ¶
func (ca *CacheAnalytics) GetDailyStats() map[string]map[string]interface{}
GetDailyStats returns daily statistics
func (*CacheAnalytics) GetHourlyStats ¶
func (ca *CacheAnalytics) GetHourlyStats() map[int]map[string]interface{}
GetHourlyStats returns hourly statistics
func (*CacheAnalytics) GetMetrics ¶
func (ca *CacheAnalytics) GetMetrics() *AnalyticsMetrics
GetMetrics returns current analytics metrics
func (*CacheAnalytics) GetPerformanceReport ¶
func (ca *CacheAnalytics) GetPerformanceReport() map[string]interface{}
GetPerformanceReport generates a comprehensive performance report
func (*CacheAnalytics) GetSlowQueries ¶
func (ca *CacheAnalytics) GetSlowQueries(limit int) []QueryStats
GetSlowQueries returns the slowest queries
func (*CacheAnalytics) GetTopQueries ¶
func (ca *CacheAnalytics) GetTopQueries(limit int) []QueryStats
GetTopQueries returns the most frequently executed queries
func (*CacheAnalytics) RecordCacheDelete ¶
func (ca *CacheAnalytics) RecordCacheDelete()
RecordCacheDelete records a cache delete operation
func (*CacheAnalytics) RecordCacheSet ¶
func (ca *CacheAnalytics) RecordCacheSet()
RecordCacheSet records a cache set operation
func (*CacheAnalytics) RecordInvalidation ¶
func (ca *CacheAnalytics) RecordInvalidation()
RecordInvalidation records a cache invalidation
func (*CacheAnalytics) RecordRequest ¶
func (ca *CacheAnalytics) RecordRequest(query string, variables map[string]interface{}, hit bool, responseTime time.Duration)
RecordRequest records a cache request
func (*CacheAnalytics) ResetMetrics ¶
func (ca *CacheAnalytics) ResetMetrics()
ResetMetrics resets all analytics metrics
type CacheInsight ¶
type CacheInsight struct { Type InsightType `json:"type"` Severity Severity `json:"severity"` Title string `json:"title"` Description string `json:"description"` Recommendation string `json:"recommendation"` Timestamp time.Time `json:"timestamp"` Metadata map[string]interface{} `json:"metadata,omitempty"` }
CacheInsight represents an insight about cache performance
type CacheMetrics ¶
type CacheMetrics struct { Hits int64 `json:"hits"` Misses int64 `json:"misses"` Sets int64 `json:"sets"` Deletes int64 `json:"deletes"` Invalidations int64 `json:"invalidations"` Size int `json:"size"` LastReset time.Time `json:"lastReset"` }
CacheMetrics holds cache performance metrics
type CacheWarmQuery ¶
type CacheWarmQuery struct { Query string `json:"query"` Variables map[string]interface{} `json:"variables,omitempty"` TTL time.Duration `json:"ttl"` Priority int `json:"priority"` }
CacheWarmQuery represents a query to warm the cache
type CacheWarmer ¶
type CacheWarmer struct {
// contains filtered or unexported fields
}
CacheWarmer manages cache warming operations
func NewCacheWarmer ¶
func NewCacheWarmer(queryCache *QueryCache, logger *slog.Logger) *CacheWarmer
NewCacheWarmer creates a new cache warmer
func (*CacheWarmer) AddWarmupQuery ¶
func (cw *CacheWarmer) AddWarmupQuery(query CacheWarmQuery)
AddWarmupQuery adds a query to the warmup list
func (*CacheWarmer) CreateDefaultWarmupQueries ¶
func (cw *CacheWarmer) CreateDefaultWarmupQueries()
CreateDefaultWarmupQueries creates default warmup queries
func (*CacheWarmer) GetWarmupQueries ¶
func (cw *CacheWarmer) GetWarmupQueries() []CacheWarmQuery
GetWarmupQueries returns the current warmup queries
func (*CacheWarmer) GetWarmupStats ¶
func (cw *CacheWarmer) GetWarmupStats() map[string]interface{}
GetWarmupStats returns statistics about cache warming
func (*CacheWarmer) IsRunning ¶
func (cw *CacheWarmer) IsRunning() bool
IsRunning returns whether the cache warmer is currently running
func (*CacheWarmer) RemoveWarmupQuery ¶
func (cw *CacheWarmer) RemoveWarmupQuery(query string)
RemoveWarmupQuery removes a query from the warmup list
func (*CacheWarmer) Start ¶
func (cw *CacheWarmer) Start(ctx context.Context, config *WarmupConfig) error
Start starts the cache warming process
func (*CacheWarmer) WarmupNow ¶
func (cw *CacheWarmer) WarmupNow(ctx context.Context, config *WarmupConfig) error
WarmupNow performs immediate cache warming
type CachedQueryResult ¶
type CachedQueryResult struct { Data interface{} `json:"data"` Errors []interface{} `json:"errors,omitempty"` Timestamp time.Time `json:"timestamp"` TTL time.Duration `json:"ttl"` QueryHash string `json:"queryHash"` Variables map[string]interface{} `json:"variables,omitempty"` Extensions map[string]interface{} `json:"extensions,omitempty"` }
CachedQueryResult represents a cached GraphQL query result
type ConditionOperator ¶
type ConditionOperator string
ConditionOperator defines the operator for conditions
const ( OperatorEquals ConditionOperator = "equals" OperatorNotEquals ConditionOperator = "not_equals" OperatorContains ConditionOperator = "contains" OperatorMatches ConditionOperator = "matches" OperatorGreater ConditionOperator = "greater" OperatorLess ConditionOperator = "less" OperatorAfter ConditionOperator = "after" OperatorBefore ConditionOperator = "before" )
type ConditionType ¶
type ConditionType string
ConditionType defines the type of invalidation condition
const ( ConditionTypeTime ConditionType = "time" ConditionTypeEvent ConditionType = "event" ConditionTypeData ConditionType = "data" ConditionTypePattern ConditionType = "pattern" ConditionTypeTag ConditionType = "tag" )
type InsightType ¶
type InsightType string
InsightType defines the type of cache insight
const ( InsightTypePerformance InsightType = "performance" InsightTypeHitRate InsightType = "hit_rate" InsightTypeMemory InsightType = "memory" InsightTypeQuery InsightType = "query" InsightTypeTTL InsightType = "ttl" )
type InvalidationCondition ¶
type InvalidationCondition struct { Type ConditionType `json:"type"` Field string `json:"field"` Operator ConditionOperator `json:"operator"` Value interface{} `json:"value"` Metadata map[string]interface{} `json:"metadata,omitempty"` }
InvalidationCondition defines a condition for cache invalidation
type InvalidationEvent ¶
type InvalidationEvent struct { Type string `json:"type"` Source string `json:"source"` Data map[string]interface{} `json:"data"` Timestamp time.Time `json:"timestamp"` Tags []string `json:"tags"` Metadata map[string]interface{} `json:"metadata,omitempty"` }
InvalidationEvent represents an event that can trigger cache invalidation
type InvalidationManager ¶
type InvalidationManager struct {
// contains filtered or unexported fields
}
InvalidationManager manages cache invalidation strategies
func NewInvalidationManager ¶
func NewInvalidationManager(queryCache *QueryCache, logger *slog.Logger) *InvalidationManager
NewInvalidationManager creates a new invalidation manager
func (*InvalidationManager) AddRule ¶
func (im *InvalidationManager) AddRule(rule *InvalidationRule) error
AddRule adds a new invalidation rule
func (*InvalidationManager) CreateDefaultRules ¶
func (im *InvalidationManager) CreateDefaultRules() error
CreateDefaultRules creates default invalidation rules
func (*InvalidationManager) ProcessEvent ¶
func (im *InvalidationManager) ProcessEvent(ctx context.Context, event *InvalidationEvent) error
ProcessEvent processes an invalidation event
func (*InvalidationManager) RegisterStrategy ¶
func (im *InvalidationManager) RegisterStrategy(name string, strategy InvalidationStrategy)
RegisterStrategy registers an invalidation strategy
func (*InvalidationManager) RemoveRule ¶
func (im *InvalidationManager) RemoveRule(ruleID string) error
RemoveRule removes an invalidation rule
type InvalidationRule ¶
type InvalidationRule struct { ID string `json:"id"` Name string `json:"name"` Pattern string `json:"pattern"` Tags []string `json:"tags"` Conditions []InvalidationCondition `json:"conditions"` Strategy InvalidationStrategy `json:"strategy"` Enabled bool `json:"enabled"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` }
InvalidationRule defines when and how to invalidate cache entries
type InvalidationStrategy ¶
type InvalidationStrategy string
InvalidationStrategy defines how cache invalidation works
const ( // InvalidationStrategyTTL - Invalidate based on TTL only InvalidationStrategyTTL InvalidationStrategy = "ttl" // InvalidationStrategyEvent - Invalidate based on events InvalidationStrategyEvent InvalidationStrategy = "event" // InvalidationStrategyHybrid - Use both TTL and events InvalidationStrategyHybrid InvalidationStrategy = "hybrid" )
type QueryCache ¶
type QueryCache struct {
// contains filtered or unexported fields
}
QueryCache represents a GraphQL query result cache
func NewQueryCache ¶
func NewQueryCache(config *QueryCacheConfig, logger *slog.Logger) (*QueryCache, error)
NewQueryCache creates a new GraphQL query cache
func (*QueryCache) Clear ¶
func (qc *QueryCache) Clear(ctx context.Context) error
Clear clears all cached entries
func (*QueryCache) Delete ¶
func (qc *QueryCache) Delete(ctx context.Context, query string, variables map[string]interface{}) error
Delete removes a cached query result
func (*QueryCache) Get ¶
func (qc *QueryCache) Get(ctx context.Context, query string, variables map[string]interface{}) (*CachedQueryResult, bool)
Get retrieves a cached query result
func (*QueryCache) GetCacheStats ¶
func (qc *QueryCache) GetCacheStats() map[string]interface{}
GetCacheStats returns detailed cache statistics
func (*QueryCache) GetMetrics ¶
func (qc *QueryCache) GetMetrics() *CacheMetrics
GetMetrics returns cache performance metrics
func (*QueryCache) InvalidateByPattern ¶
func (qc *QueryCache) InvalidateByPattern(ctx context.Context, pattern string) error
InvalidateByPattern invalidates cache entries matching a pattern
func (*QueryCache) InvalidateByTags ¶
func (qc *QueryCache) InvalidateByTags(ctx context.Context, tags []string) error
InvalidateByTags invalidates cache entries with specific tags
func (*QueryCache) PublishInvalidation ¶
func (qc *QueryCache) PublishInvalidation(pattern string)
PublishInvalidation publishes an invalidation event
func (*QueryCache) ResetMetrics ¶
func (qc *QueryCache) ResetMetrics()
ResetMetrics resets the cache metrics
func (*QueryCache) Set ¶
func (qc *QueryCache) Set(ctx context.Context, query string, variables map[string]interface{}, data interface{}, errors []interface{}, ttl time.Duration) error
Set stores a query result in the cache
func (*QueryCache) SubscribeToInvalidation ¶
func (qc *QueryCache) SubscribeToInvalidation(pattern string) <-chan string
SubscribeToInvalidation subscribes to cache invalidation events
func (*QueryCache) UnsubscribeFromInvalidation ¶
func (qc *QueryCache) UnsubscribeFromInvalidation(pattern string, ch <-chan string)
UnsubscribeFromInvalidation unsubscribes from cache invalidation events
func (*QueryCache) WarmCache ¶
func (qc *QueryCache) WarmCache(ctx context.Context, queries []CacheWarmQuery) error
WarmCache preloads the cache with common queries
type QueryCacheConfig ¶
type QueryCacheConfig struct { DefaultTTL time.Duration `json:"defaultTTL"` MaxCacheSize int `json:"maxCacheSize"` EnableCompression bool `json:"enableCompression"` EnableMetrics bool `json:"enableMetrics"` InvalidationStrategy InvalidationStrategy `json:"invalidationStrategy"` }
QueryCacheConfig holds configuration for the query cache
func DefaultQueryCacheConfig ¶
func DefaultQueryCacheConfig() *QueryCacheConfig
DefaultQueryCacheConfig returns the default cache configuration
type QueryStats ¶
type QueryStats struct { Query string `json:"query"` Hash string `json:"hash"` Count int64 `json:"count"` Hits int64 `json:"hits"` Misses int64 `json:"misses"` AverageTime time.Duration `json:"averageTime"` TotalTime time.Duration `json:"totalTime"` LastExecuted time.Time `json:"lastExecuted"` HitRate float64 `json:"hitRate"` Variables map[string]interface{} `json:"variables,omitempty"` }
QueryStats holds statistics for a specific query
type WarmupConfig ¶
type WarmupConfig struct { Strategy WarmupStrategy `json:"strategy"` Interval time.Duration `json:"interval"` Concurrency int `json:"concurrency"` MaxRetries int `json:"maxRetries"` RetryDelay time.Duration `json:"retryDelay"` Enabled bool `json:"enabled"` }
WarmupConfig holds configuration for cache warming
func DefaultWarmupConfig ¶
func DefaultWarmupConfig() *WarmupConfig
DefaultWarmupConfig returns the default warmup configuration
type WarmupStrategy ¶
type WarmupStrategy string
WarmupStrategy defines how cache warming should be performed
const ( // WarmupStrategyImmediate - Warm cache immediately on startup WarmupStrategyImmediate WarmupStrategy = "immediate" // WarmupStrategyScheduled - Warm cache on a schedule WarmupStrategyScheduled WarmupStrategy = "scheduled" // WarmupStrategyOnDemand - Warm cache on demand WarmupStrategyOnDemand WarmupStrategy = "on_demand" )