using System; using System.Collections.Generic; using System.Text; namespace Apewer.Web { /// 缓存控制的值。 public static class CacheControl { /// 不缓存。 public const string Disabled = "no-cache, no-store, must-revalidate"; /// 1 天的秒数。 public const int Day = 86400; /// 30 天的秒数。 public const int Month = 259200; /// 365 天的秒数。 public const int Year = 31536000; /// 构建缓存指令,此指令允许所有缓存。 /// 浏览器的缓存秒数。 /// 代理服务器的缓存秒数。 public static string Public(int maxAge, int sMaxAge) { if (maxAge < 0) throw new ArgumentOutOfRangeException(nameof(maxAge)); if (sMaxAge < 0) throw new ArgumentOutOfRangeException(nameof(sMaxAge)); return $"public, max-age={maxAge}, s-maxage={sMaxAge}, must-revalidate"; } /// 构建缓存指令,此指令仅允许浏览器缓存。 /// 浏览器的缓存秒数。 public static string Private(int maxAge) { if (maxAge < 0) throw new ArgumentOutOfRangeException(nameof(maxAge)); return $"private, max-age={maxAge}, must-revalidate"; } } }