You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TimeCacheControlAttribute.cs 1.0KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using iiie.CacheControl.Attributes;
  3. using iiie.CacheControl.Business.OutputCache;
  4. using iiie.CacheControl.DBO;
  5. namespace iiie.CacheControl.Business.Attributes
  6. {
  7. /// <summary>
  8. /// A basic cache control based on time
  9. /// </summary>
  10. public class TimeCacheControlAttribute : CacheControlAttribute
  11. {
  12. /// <summary>
  13. /// The number of seconds the cache is valid
  14. /// </summary>
  15. protected int Seconds { get; set; }
  16. /// <summary>
  17. /// Contruct a cache control based on time
  18. /// </summary>
  19. public TimeCacheControlAttribute(int seconds)
  20. {
  21. Seconds = seconds;
  22. }
  23. /// <summary>
  24. /// Check if data has been cached for less than Senconds seconds
  25. /// </summary>
  26. /// <param name="data">The cached data</param>
  27. /// <returns>True if cache is still valid</returns>
  28. protected override bool IsValid(CacheDbo data)
  29. {
  30. return data.Date.AddSeconds(Seconds) >= DateTime.Now;
  31. }
  32. }
  33. }