using System; using iiie.CacheControl.Attributes; using iiie.CacheControl.Business.OutputCache; using iiie.CacheControl.DBO; namespace iiie.CacheControl.Business.Attributes { /// /// A basic cache control based on time /// public class TimeCacheControlAttribute : CacheControlAttribute { /// /// The number of seconds the cache is valid /// protected int Seconds { get; set; } /// /// Contruct a cache control based on time /// /// The number of seconds the cache is valid /// Indicates if the client can reuse cached data without asking origin server /// Indicates if the query string must be used to control cache /// Define the cache type used to store cache public TimeCacheControlAttribute(int seconds, bool mustRevalidate = true, bool excludeQueryStringFromCacheKey = false, OutputCacheType cacheType = OutputCacheType.Memory) { Seconds = seconds; MustRevalidate = mustRevalidate; ExcludeQueryStringFromCacheKey = excludeQueryStringFromCacheKey; CacheType = cacheType; } /// /// Check if data has been cached for less than Senconds seconds /// /// The cached data /// True if cache is still valid protected override bool IsValid(CacheDbo data) { return data.Date.AddSeconds(Seconds) >= DateTime.Now; } } }