Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

TimeCacheControlAttribute.cs 1.1KB

12345678910111213141516171819202122232425262728293031323334353637
  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, bool excludeGet = false, bool excludePost = false)
  19. {
  20. Seconds = seconds;
  21. ExcludePostFromCacheKey = excludePost;
  22. ExcludeQueryStringFromCacheKey = excludeGet;
  23. }
  24. /// <summary>
  25. /// Check if data has been cached for less than Senconds seconds
  26. /// </summary>
  27. /// <param name="data">The cached data</param>
  28. /// <returns>True if cache is still valid</returns>
  29. protected override bool IsValid(CacheDbo data)
  30. {
  31. return data.Date.AddSeconds(Seconds) >= DateTime.Now;
  32. }
  33. }
  34. }