| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- //
- // System.Web.HttpCachePolicy
- //
- // Authors:
- // Patrik Torstensson ([email protected])
- // Tim Coleman ([email protected])
- // Gonzalo Paniagua Javier ([email protected])
- //
- using System;
- using System.Collections;
- using System.Text;
- using System.Web.UI;
- namespace System.Web {
- public sealed class HttpCachePolicy {
- internal HttpCachePolicy ()
- {
- }
- #region Fields
- HttpCacheVaryByHeaders varyByHeaders = new HttpCacheVaryByHeaders ();
- HttpCacheVaryByParams varyByParams = new HttpCacheVaryByParams ();
- ArrayList validationCallbacks;
- StringBuilder cacheExtension;
- HttpCacheability cacheability;
- string etag;
- bool etagFromFileDependencies;
- bool haveExpireDate;
- DateTime expireDate;
- bool haveLastModified;
- DateTime lastModified;
- bool lastModifiedFromFileDependencies;
- bool noServerCaching;
- bool noStore;
- bool noTransforms;
- HttpCacheRevalidation revalidation;
- bool slidingSpiration;
- bool validUntilExpires;
- string varyByCustom;
- bool haveMaxAge;
- TimeSpan maxAge;
- bool haveProxyMaxAge;
- TimeSpan proxyMaxAge;
- ArrayList fields;
- bool slidingExpiration;
- #endregion
- #region Properties
- public HttpCacheVaryByHeaders VaryByHeaders {
- get { return varyByHeaders; }
- }
- public HttpCacheVaryByParams VaryByParams {
- get { return varyByParams; }
- }
- #endregion // Properties
- #region Methods
- public void AddValidationCallback (HttpCacheValidateHandler handler, object data)
- {
- if (handler == null)
- throw new ArgumentNullException ("handler");
- if (validationCallbacks == null)
- validationCallbacks = new ArrayList ();
- validationCallbacks.Add (new Pair (handler, data));
- }
- public void AppendCacheExtension (string extension)
- {
- if (extension == null)
- throw new ArgumentNullException ("extension");
- if (cacheExtension == null)
- cacheExtension = new StringBuilder (extension);
- else
- cacheExtension.Append (", " + extension);
- }
- public void SetCacheability (HttpCacheability cacheability)
- {
- if (cacheability < HttpCacheability.NoCache || cacheability > HttpCacheability.Public)
- throw new ArgumentOutOfRangeException ("cacheability");
- if (cacheability > this.cacheability)
- return;
- this.cacheability = cacheability;
- }
- public void SetCacheability (HttpCacheability cacheability, string field)
- {
- if (field == null)
- throw new ArgumentNullException ("field");
- if (cacheability != HttpCacheability.Private &&
- cacheability != HttpCacheability.NoCache)
- throw new ArgumentException ("Must be NoCache or Private", "cacheability");
- if (fields == null)
- fields = new ArrayList ();
- fields.Add (new Pair (cacheability, field));
- }
- public void SetETag (string etag)
- {
- if (etag == null)
- throw new ArgumentNullException ("etag");
- if (this.etag != null)
- throw new InvalidOperationException ("The ETag header has already been set");
- if (etagFromFileDependencies)
- throw new InvalidOperationException ("SetEtagFromFileDependencies has already been called");
- this.etag = etag;
- }
- public void SetETagFromFileDependencies ()
- {
- if (this.etag != null)
- throw new InvalidOperationException ("The ETag header has already been set");
- etagFromFileDependencies = true;
- }
- public void SetExpires (DateTime date)
- {
- if (haveExpireDate && date > expireDate)
- return;
- haveExpireDate = true;
- expireDate = date;
- }
- public void SetLastModified (DateTime date)
- {
- if (date > DateTime.Now)
- throw new ArgumentOutOfRangeException ("date");
- if (haveLastModified && date < lastModified)
- return;
- haveLastModified = true;
- lastModified = date;
- }
- public void SetLastModifiedFromFileDependencies ()
- {
- lastModifiedFromFileDependencies = true;
- }
- public void SetMaxAge (TimeSpan date)
- {
- if (date < TimeSpan.Zero)
- throw new ArgumentOutOfRangeException ("date");
- if (haveMaxAge && maxAge < date)
- return;
- proxyMaxAge = date;
- }
- public void SetNoServerCaching ()
- {
- noServerCaching = true;
- }
- public void SetNoStore ()
- {
- noStore = true;
- }
- public void SetNoTransforms ()
- {
- noTransforms = true;
- }
- public void SetProxyMaxAge (TimeSpan delta)
- {
- if (delta < TimeSpan.Zero)
- throw new ArgumentOutOfRangeException ("delta");
- if (haveProxyMaxAge && proxyMaxAge < delta)
- return;
- proxyMaxAge = delta;
- }
- public void SetRevalidation (HttpCacheRevalidation revalidation)
- {
- if (revalidation < HttpCacheRevalidation.AllCaches ||
- revalidation > HttpCacheRevalidation.None)
- throw new ArgumentOutOfRangeException ("revalidation");
- if (this.revalidation > revalidation)
- this.revalidation = revalidation;
- }
- public void SetSlidingExpiration (bool slide)
- {
- slidingExpiration = slide;
- }
- public void SetValidUntilExpires (bool validUntilExpires)
- {
- this.validUntilExpires = validUntilExpires;
- }
- public void SetVaryByCustom (string custom)
- {
- if (custom == null)
- throw new ArgumentNullException ("custom");
- if (varyByCustom != null)
- throw new InvalidOperationException ("VaryByCustom has already been set.");
- varyByCustom = custom;
- }
- #endregion // Methods
- }
- }
|