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 1014B

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