1234567891011121314151617181920212223242526272829303132333435 |
- using System;
- using iiie.CacheControl.Attributes;
- 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;
- }
- }
- }
|