// ----------------------------------------------------------------------------- // IAdvisoryCacheService.cs // Sprint: SPRINT_8200_0013_0001_GW_valkey_advisory_cache // Task: VCACHE-8200-010 // Description: Interface for Valkey-based canonical advisory caching // ----------------------------------------------------------------------------- using StellaOps.Concelier.Core.Canonical; namespace StellaOps.Concelier.Cache.Valkey; /// /// Valkey-based cache for canonical advisories. /// Provides read-through caching with TTL based on interest score. /// public interface IAdvisoryCacheService { // === Read Operations === /// /// Get canonical advisory by merge hash (cache-first). /// /// The merge hash identifying the canonical. /// Cancellation token. /// The cached advisory, or null if not found. Task GetAsync(string mergeHash, CancellationToken cancellationToken = default); /// /// Get canonical advisories by PURL (uses index). /// /// The PURL to lookup. /// Cancellation token. /// List of advisories affecting this PURL. Task> GetByPurlAsync(string purl, CancellationToken cancellationToken = default); /// /// Get canonical advisory by CVE (uses mapping). /// /// The CVE identifier. /// Cancellation token. /// The primary canonical for this CVE, or null. Task GetByCveAsync(string cve, CancellationToken cancellationToken = default); /// /// Get hot advisories (top N by interest score). /// /// Maximum number to return. /// Cancellation token. /// List of hot advisories in descending score order. Task> GetHotAsync(int limit = 100, CancellationToken cancellationToken = default); // === Write Operations === /// /// Cache canonical advisory with TTL based on interest score. /// /// The advisory to cache. /// Optional interest score (0.0-1.0) for TTL calculation. /// Cancellation token. Task SetAsync(CanonicalAdvisory advisory, double? interestScore = null, CancellationToken cancellationToken = default); /// /// Invalidate cached advisory. /// /// The merge hash to invalidate. /// Cancellation token. Task InvalidateAsync(string mergeHash, CancellationToken cancellationToken = default); /// /// Update interest score (affects TTL and hot set membership). /// /// The merge hash to update. /// The new interest score (0.0-1.0). /// Cancellation token. Task UpdateScoreAsync(string mergeHash, double score, CancellationToken cancellationToken = default); // === Index Operations === /// /// Add merge hash to PURL index. /// /// The PURL to index. /// The merge hash to add. /// Cancellation token. Task IndexPurlAsync(string purl, string mergeHash, CancellationToken cancellationToken = default); /// /// Remove merge hash from PURL index. /// /// The PURL to unindex. /// The merge hash to remove. /// Cancellation token. Task UnindexPurlAsync(string purl, string mergeHash, CancellationToken cancellationToken = default); /// /// Set CVE to merge hash mapping. /// /// The CVE identifier. /// The canonical merge hash. /// Cancellation token. Task IndexCveAsync(string cve, string mergeHash, CancellationToken cancellationToken = default); // === Maintenance === /// /// Warm cache with hot advisories from database. /// /// Maximum number of advisories to preload. /// Cancellation token. Task WarmupAsync(int limit = 1000, CancellationToken cancellationToken = default); /// /// Get cache statistics. /// /// Cancellation token. /// Current cache statistics. Task GetStatisticsAsync(CancellationToken cancellationToken = default); /// /// Check if the cache service is healthy. /// /// Cancellation token. /// True if the cache is reachable and operational. Task IsHealthyAsync(CancellationToken cancellationToken = default); } /// /// Cache statistics for monitoring and debugging. /// public sealed record CacheStatistics { /// Total cache hits. public long Hits { get; init; } /// Total cache misses. public long Misses { get; init; } /// Cache hit rate (0.0-1.0). public double HitRate => Hits + Misses > 0 ? (double)Hits / (Hits + Misses) : 0; /// Current size of the hot advisory set. public long HotSetSize { get; init; } /// Approximate total cached advisories. public long TotalCachedAdvisories { get; init; } /// When the cache was last warmed up. public DateTimeOffset? LastWarmup { get; init; } /// Whether the cache service is currently healthy. public bool IsHealthy { get; init; } /// Valkey server info string. public string? ServerInfo { get; init; } }