using System; using System.Collections.Generic; using System.Text; namespace System.Net.ApiService { public class Response_CacheControl { [Flags] public enum eCacheControl { none = 0, no_cache = 1, no_store = 2, no_transform = 4, must_revalidate = 8, public_cache = 16, private_cache = 32, proxy_revalidate = 64 } private TimeSpan _maxAge; private TimeSpan _sMaxAge; private eCacheControl _options; public Response_CacheControl(TimeSpan MaxAge) { this._maxAge = MaxAge; } public Response_CacheControl(TimeSpan MaxAge, TimeSpan SMaxAge) { this._maxAge = MaxAge; this._sMaxAge = SMaxAge; } public Response_CacheControl(TimeSpan MaxAge, eCacheControl Options) { this._maxAge = MaxAge; this._options = Options; } public Response_CacheControl(eCacheControl Options) { this._options = Options; } public Response_CacheControl(TimeSpan MaxAge, TimeSpan SMaxAge, eCacheControl Options) { this._maxAge = MaxAge; this._sMaxAge = SMaxAge; this._options = Options; } public bool IsSet { get { return this._maxAge.TotalSeconds > 0 || this._sMaxAge.TotalSeconds > 0 || this._options != eCacheControl.none; } } public TimeSpan MaxAge { get => this._maxAge; set { if (value == null) { this._maxAge = new TimeSpan(0); } else { this._maxAge = value; } } } public TimeSpan SMaxAge { get => this._sMaxAge; set { if (value == null) { this._sMaxAge = new TimeSpan(0); } else { this._sMaxAge = value; } } } public eCacheControl Options { get => this._options; set { this._options = value; } } public override string ToString() { string s = ""; if (this._maxAge.TotalSeconds > 0) s += (s==""?"":", ") + "max-age: " + this._maxAge.TotalSeconds; if (this._sMaxAge.TotalSeconds > 0) s += (s == "" ? "" : ", ") + "s-maxage: " + this._maxAge.TotalSeconds; if (this._options != eCacheControl.none) { if((this._options & eCacheControl.must_revalidate) == this._options) s += (s == "" ? "" : ", ") + "must-revalidate"; if ((this._options & eCacheControl.no_cache) == this._options) s += (s == "" ? "" : ", ") + "no-cache"; if ((this._options & eCacheControl.no_store) == this._options) s += (s == "" ? "" : ", ") + "no-store"; if ((this._options & eCacheControl.no_transform) == this._options) s += (s == "" ? "" : ", ") + "no-transform"; if ((this._options & eCacheControl.private_cache) == this._options) s += (s == "" ? "" : ", ") + "private"; if ((this._options & eCacheControl.public_cache) == this._options) s += (s == "" ? "" : ", ") + "public"; if ((this._options & eCacheControl.proxy_revalidate) == this._options) s += (s == "" ? "" : ", ") + "proxy-revalidate"; } return s; } } }