123456789101112131415161718192021222324252627282930313233343536 |
- using System;
- using iiie.CacheControl.Attributes;
- using iiie.CacheControl.Business.OutputCache;
- using iiie.CacheControl.DBO;
-
- namespace iiie.CacheControl.Business.Attributes
- {
- /// <summary>
- /// A basic cache control based on time
- /// </summary>
- public class TimeCacheControlAttribute : CacheControlAttribute
- {
- /// <summary>
- /// The number of seconds the cache is valid
- /// </summary>
- protected int Seconds { get; set; }
-
- /// <summary>
- /// Contruct a cache control based on time
- /// </summary>
- public TimeCacheControlAttribute(int seconds)
- {
- Seconds = seconds;
- }
-
- /// <summary>
- /// Check if data has been cached for less than Senconds seconds
- /// </summary>
- /// <param name="data">The cached data</param>
- /// <returns>True if cache is still valid</returns>
- protected override bool IsValid(CacheDbo data)
- {
- return data.Date.AddSeconds(Seconds) >= DateTime.Now;
- }
- }
- }
|