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.

44 lines
1.5 KiB

11 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Apewer.Web
  5. {
  6. /// <summary>缓存控制的值。</summary>
  7. public static class CacheControl
  8. {
  9. /// <summary>不缓存。</summary>
  10. public const string Disabled = "no-cache, no-store, must-revalidate";
  11. /// <summary>1 天的秒数。</summary>
  12. public const int Day = 86400;
  13. /// <summary>30 天的秒数。</summary>
  14. public const int Month = 259200;
  15. /// <summary>365 天的秒数。</summary>
  16. public const int Year = 31536000;
  17. /// <summary>构建缓存指令,此指令允许所有缓存。</summary>
  18. /// <param name="maxAge">浏览器的缓存秒数。</param>
  19. /// <param name="sMaxAge">代理服务器的缓存秒数。</param>
  20. public static string Public(int maxAge, int sMaxAge)
  21. {
  22. if (maxAge < 0) throw new ArgumentOutOfRangeException(nameof(maxAge));
  23. if (sMaxAge < 0) throw new ArgumentOutOfRangeException(nameof(sMaxAge));
  24. return $"public, max-age={maxAge}, s-maxage={sMaxAge}, must-revalidate";
  25. }
  26. /// <summary>构建缓存指令,此指令仅允许浏览器缓存。</summary>
  27. /// <param name="maxAge">浏览器的缓存秒数。</param>
  28. public static string Private(int maxAge)
  29. {
  30. if (maxAge < 0) throw new ArgumentOutOfRangeException(nameof(maxAge));
  31. return $"private, max-age={maxAge}, must-revalidate";
  32. }
  33. }
  34. }