Пример #1
0
        protected void SetClientCacheHeader(DateTime?LastModified, string Etag, HttpCacheability CacheKind, bool ReValidate = true)
        {
            if (!EnableClientCache || LastModified == null && Etag == null)
            {
                return;
            }
            HttpCachePolicyBase cp = Response.Cache;

            cp.AppendCacheExtension("max-age=" + 3600 * MaxClientCacheAgeInHours);
            if (ReValidate)
            {
                cp.AppendCacheExtension("must-revalidate");
                cp.AppendCacheExtension("proxy-revalidate");
            }
            cp.SetCacheability(CacheKind);
            cp.SetOmitVaryStar(false);
            if (LastModified != null)
            {
                cp.SetLastModified(LastModified.Value);
            }
            cp.SetExpires(DateTime.UtcNow.AddHours(MaxClientCacheAgeInHours));
            if (Etag != null)
            {
                cp.SetETag(Etag);
            }
        }
Пример #2
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CacheAttribute"/> class.
		/// </summary>
		/// <param name="cacheability">Sets the Cache-Control HTTP header. 
		/// The Cache-Control HTTP header controls how documents are to be cached on the network.</param>
		public CacheAttribute(HttpCacheability cacheability)
		{
			this.cacheability = cacheability;

			allowInHistory = true;
			validUntilExpires = true;
		}
Пример #3
0
        public void SetCacheability(HttpCacheability cacheability, string field)
        {
            if (field == null)
            {
                throw new ArgumentNullException("field");
            }
            switch (cacheability)
            {
            case HttpCacheability.NoCache:
                if (this._noCacheFields == null)
                {
                    this._noCacheFields = new HttpDictionary();
                }
                this._noCacheFields.SetValue(field, field);
                break;

            case HttpCacheability.Private:
                if (this._privateFields == null)
                {
                    this._privateFields = new HttpDictionary();
                }
                this._privateFields.SetValue(field, field);
                break;

            default:
                throw new ArgumentException(System.Web.SR.GetString("Cacheability_for_field_must_be_private_or_nocache"), "cacheability");
            }
            this.Dirtied();
        }
 public CacheableFileContentResult(byte[] fileContents, string contentType, DateTime lastModifed,
     HttpCacheability cacheability)
     : base(fileContents, contentType)
 {
     LastModified = lastModifed;
     Cacheability = cacheability;
 }
Пример #5
0
 public CacheableFileContentResult(byte[] fileContents, string contentType, DateTime lastModifed,
                                   HttpCacheability cacheability)
     : base(fileContents, contentType)
 {
     LastModified = lastModifed;
     Cacheability = cacheability;
 }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CacheAttribute"/> class.
        /// </summary>
        /// <param name="cacheability">Sets the Cache-Control HTTP header.
        /// The Cache-Control HTTP header controls how documents are to be cached on the network.</param>
        public CacheAttribute(HttpCacheability cacheability)
        {
            this.cacheability = cacheability;

            allowInHistory    = true;
            validUntilExpires = true;
            revalidation      = HttpCacheRevalidation.None;
        }
Пример #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BrowserCacheAttribute"/> class.
 /// </summary>
 /// <param name="cacheability"></param>
 /// <param name="revalidation"></param>
 /// <param name="cacheDuration"></param>
 /// <param name="maxProxyAge"></param>
 public BrowserCacheAttribute(HttpCacheability cacheability, HttpCacheRevalidation revalidation, TimeSpan cacheDuration, TimeSpan maxProxyAge)
     : base()
 {
     this.Revalidation  = revalidation;
     this.Cacheability  = cacheability;
     this.CacheDuration = cacheDuration;
     this.MaxProxyAge   = maxProxyAge;
 }
Пример #8
0
 // 构造器
 public ResponseEncoder(ResponseType dataType, string mimeType = null, string fileName = null, int cacheSeconds = 0, HttpCacheability cacheLocation = HttpCacheability.ServerAndPrivate)
 {
     this.DataType      = dataType;
     this.MimeType      = mimeType;
     this.FileName      = fileName;
     this.CacheSeconds  = cacheSeconds;
     this.CacheLocation = cacheLocation;
 }
Пример #9
0
 public static NotModifiedResult NotModified(this Controller controller, HttpCacheability cacheability, DateTime expires)
 {
     return(new NotModifiedResult
     {
         Cacheability = cacheability,
         Expires = expires
     });
 }
        public void SetCacheability(HttpCacheability cacheability)
        {
            // http://www.mnot.net/blog/2007/05/15/expires_max-age
            // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2012/201209/20120925-varnish


            this.InternalResponse.AddHeader("Cache-Control", "max-age=3600");
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BrowserCacheAttribute"/> class.
 /// </summary>
 /// <param name="cacheability"></param>
 /// <param name="revalidation"></param>
 /// <param name="cacheDuration"></param>
 /// <param name="maxProxyAge"></param>
 public BrowserCacheAttribute(HttpCacheability cacheability, HttpCacheRevalidation revalidation, TimeSpan cacheDuration, TimeSpan maxProxyAge)
     : base()
 {
     this.Revalidation = revalidation;
     this.Cacheability = cacheability;
     this.CacheDuration = cacheDuration;
     this.MaxProxyAge = maxProxyAge;
 }
 public CacheableContentResult(string contentType, Func<byte[]> getContent, DateTime? lastModified = null, string etag = null, HttpCacheability? cacheability = null)
 {
     this.ContentType = contentType;
     this.GetContent = getContent;
     this.LastModified = lastModified;
     this.ETag = etag ?? "";
     this.Cacheability = cacheability;
 }
Пример #13
0
        public ETagFilter(HttpResponseBase response, HttpRequestBase request, int duration, HttpCacheability cachecontrol)
        {
            _response = response;
            _request  = request;
            _filter   = response.Filter;

            this.duration     = duration;
            this.cachecontrol = cachecontrol;
        }
        public void SetCacheability(HttpCacheability cacheability)
        {
            // http://www.mnot.net/blog/2007/05/15/expires_max-age
            // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2012/201209/20120925-varnish


            this.InternalResponse.AddHeader("Cache-Control", "max-age=3600");

        }
Пример #15
0
        public void SetMaxAgeHeader(TimeSpan maxAge, HttpCacheability cacheability)
        {
            string maxAgeString = string.Format(
                CultureInfo.InvariantCulture,
                "max-age={0}",
                (int)maxAge.TotalSeconds);

            AddResponseHeader("Cache-Control", maxAgeString);
        }
        public void SetCacheability(HttpCacheability cacheability)
        {
            // set by
            // Z:\jsc.svn\core\ScriptCoreLibAndroid\ScriptCoreLibAndroid\BCLImplementation\System\Web\HttpResponse.cs

            if (vSetCacheability != null)
            {
                vSetCacheability(cacheability);
            }
        }
Пример #17
0
        public void SetCacheability(HttpCacheability cacheability)
        {
            // Cache-Control:private

            if (cacheability == HttpCacheability.Private)
            {
                this.InternalResponse.AddHeader("Cache-Control", "private");
                return;
            }
            this.InternalResponse.AddHeader("Cache-Control", "public");
        }
Пример #18
0
 public static void OutputCache(this HttpResponseBase response,
                                int numberOfSeconds,
                                bool sliding = false,
                                IEnumerable<string> varyByParams = null,
                                IEnumerable<string> varyByHeaders = null,
                                IEnumerable<string> varyByContentEncodings = null,
                                HttpCacheability cacheability = HttpCacheability.Public)
 {
     OutputCache(new HttpContextWrapper(HttpContext.Current), response.Cache, numberOfSeconds, sliding, varyByParams, varyByHeaders, varyByContentEncodings,
                 cacheability);
 }
 public static void OutputCache(this HttpResponseBase response,
                                int numberOfSeconds,
                                bool sliding = false,
                                IEnumerable <string> varyByParams           = null,
                                IEnumerable <string> varyByHeaders          = null,
                                IEnumerable <string> varyByContentEncodings = null,
                                HttpCacheability cacheability = HttpCacheability.Public)
 {
     OutputCache(new HttpContextWrapper(HttpContext.Current), response.Cache, numberOfSeconds, sliding, varyByParams, varyByHeaders, varyByContentEncodings,
                 cacheability);
 }
        public void SetCacheability(HttpCacheability cacheability)
        {
            // set by
            // Z:\jsc.svn\core\ScriptCoreLibAndroid\ScriptCoreLibAndroid\BCLImplementation\System\Web\HttpResponse.cs

            if (vSetCacheability != null)
                vSetCacheability(cacheability);



        }
Пример #21
0
        /// <summary>设置页面缓存</summary>
        /// <param name="context">网页上下文</param>
        /// <param name="cacheSeconds">缓存秒数</param>
        /// <param name="varyByParam">缓存参数名称</param>
        /// <remarks>
        /// ashx 的页面缓存不允许写语句:<%@ OutputCache Duration="60" VaryByParam="*" %>
        /// 故可直接调用本方法实现缓存。
        /// 参考:https://stackoverflow.com/questions/1109768/how-to-use-output-caching-on-ashx-handler
        /// </remarks>
        public static void SetCache(HttpContext context, int cacheSeconds = 60, HttpCacheability cacheLocation = HttpCacheability.ServerAndPrivate, string varyByParam = "*")
        {
            TimeSpan        ts          = new TimeSpan(0, 0, 0, cacheSeconds);
            HttpCachePolicy cachePolicy = context.Response.Cache;

            cachePolicy.SetCacheability(cacheLocation);
            cachePolicy.VaryByParams[varyByParam] = true;
            cachePolicy.SetExpires(DateTime.Now.Add(ts));
            cachePolicy.SetMaxAge(ts);
            cachePolicy.SetValidUntilExpires(true);
        }
Пример #22
0
 public void SetCacheability(HttpCacheability cacheability)
 {
     if ((cacheability < HttpCacheability.NoCache) || (HttpCacheability.ServerAndPrivate < cacheability))
     {
         throw new ArgumentOutOfRangeException("cacheability");
     }
     if (s_cacheabilityValues[(int)cacheability] < s_cacheabilityValues[(int)this._cacheability])
     {
         this.Dirtied();
         this._cacheability = cacheability;
     }
 }
Пример #23
0
        /// <summary>
        /// Sets the Cache-Control HTTP header. The Cache-Control HTTP header controls how documents are to be cached on the network.
        /// </summary>
        /// <param name="cacheability">The HttpCacheability enumeration value to set the header to.</param>
        /// <param name="field">The cache control extension to add to the header.</param>
        public void SetCacheability(HttpCacheability cacheability, string field)
        {
            switch (cacheability)
            {
            case HttpCacheability.Server:
            case HttpCacheability.ServerAndNoCache:
            case HttpCacheability.ServerAndPrivate:
                throw new ArgumentOutOfRangeException("Server caching is not currently supported by Padarn");
            }

            m_cacheability   = cacheability;
            m_cacheExtension = field;
        }
Пример #24
0
        public static BundleCollection ApplyHashCache(this BundleCollection bundleCollection, bool addHashToPath = true,
                                                      bool useServerCache = false, HttpCacheability httpCacheability = HttpCacheability.NoCache, string hashPathParameterName = null)
        {
            var transform = new HashCacheTransform()
            {
                AddHashToPath         = addHashToPath,
                HttpCacheability      = httpCacheability,
                HashPathParameterName = hashPathParameterName,
                UseServerCache        = useServerCache
            };

            bundleCollection.ForEach(bundle => bundle.Transforms.Add(transform));
            return(bundleCollection);
        }
Пример #25
0
        //
        // This one now allows the full range of Cacheabilities.
        //
        public void SetCacheability(HttpCacheability cacheability)
        {
            if (cacheability < HttpCacheability.NoCache || cacheability > HttpCacheability.ServerAndPrivate)
            {
                throw new ArgumentOutOfRangeException("cacheability");
            }

            if (Cacheability > 0 && cacheability > Cacheability)
            {
                return;
            }

            Cacheability = cacheability;
        }
Пример #26
0
        public static void SetCacheControlHeaders(int cacheForSeconds, HttpCacheability httpCacheability)
        {
            var cache = HttpContext.Current.Response.Cache;

            cache.SetCacheability(httpCacheability);
            if (httpCacheability == HttpCacheability.NoCache)
            {
                cache.SetNoStore();
                cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
                cache.SetValidUntilExpires(false);
            }
            cache.SetMaxAge(new TimeSpan(0, 0, cacheForSeconds));
            cache.SetSlidingExpiration(true);  // max-age does not appear in response header without this...
        }
Пример #27
0
        /// <summary>
        /// 设置 cache-control 标头为 HttpCacheability 值之一
        /// </summary>
        /// <param name="cacheability">缓存可用性</param>
        public override void SetCacheability(HttpCacheability cacheability)
        {
            switch (cacheability)
            {
            case HttpCacheability.NoCache:
            case HttpCacheability.Private:
            case HttpCacheability.Public:
                _cacheability = cacheability;
                break;

            default:
                throw new ArgumentException("cacheability", "不受支持的 Cacheablity 值");
            }
        }
        private static void SetResponseParameters(HttpResponseBase response, HttpCacheability defaultCacheability,
                                                  Entity attachment, Entity webfile, ICollection <byte> data)
        {
            response.StatusCode  = (int)HttpStatusCode.OK;
            response.ContentType = attachment.GetAttributeValue <string>("mimetype");

            var contentDispositionText = "inline";

            if (webfile != null)
            {
                var contentDispositionOptionSetValue = webfile.GetAttributeValue <OptionSetValue>("adx_contentdisposition");

                if (contentDispositionOptionSetValue != null)
                {
                    switch (contentDispositionOptionSetValue.Value)
                    {
                    case 756150000:                             // inline
                        contentDispositionText = "inline";
                        break;

                    case 756150001:                             // attachment
                        contentDispositionText = "attachment";
                        break;

                    default:
                        contentDispositionText = "inline";
                        break;
                    }
                }
            }

            if (string.Equals(response.ContentType, "text/html", StringComparison.OrdinalIgnoreCase) ||
                string.Equals(response.ContentType, "application/octet-stream", StringComparison.OrdinalIgnoreCase))
            {
                contentDispositionText = "attachment";
            }

            var contentDisposition = new StringBuilder(contentDispositionText);

            AppendFilenameToContentDisposition(attachment, contentDisposition);

            response.AppendHeader("Content-Disposition", contentDisposition.ToString());
            response.AppendHeader("Content-Length", data.Count.ToString(CultureInfo.InvariantCulture));

            var section = PortalCrmConfigurationManager.GetPortalCrmSection();
            var policy  = section.CachePolicy.Annotation;

            Utility.SetResponseCachePolicy(policy, response, defaultCacheability);
        }
Пример #29
0
        /// <summary>
        /// 设置 cache-control 标头为 HttpCacheability 值之一
        /// </summary>
        /// <param name="cacheability">缓存可用性</param>
        public override void SetCacheability(HttpCacheability cacheability)
        {
            switch (cacheability)
            {
            case HttpCacheability.NoCache:
            case HttpCacheability.Private:
            case HttpCacheability.Public:
                _cachePolicy.SetCacheability(cacheability);
                break;


            default:
                throw new InvalidOperationException();
            }
        }
Пример #30
0
        /// <summary>
        ///  Sets the http response parameters for status code, caching, and headers.
        /// </summary>
        private static void SetResponseParameters(HttpResponse response, HttpCacheability defaultCacheability, Entity salesLiteratureItem, byte[] data)
        {
            response.StatusCode  = (int)HttpStatusCode.OK;
            response.ContentType = salesLiteratureItem.GetAttributeValue <string>("mimetype");

            const string contentDispositionText = "inline";

            var contentDisposition = new StringBuilder(contentDispositionText);

            AppendFilenameToContentDisposition(salesLiteratureItem, contentDisposition);

            response.AppendHeader("Content-Disposition", contentDisposition.ToString());
            response.AppendHeader("Content-Length", data.Length.ToString(CultureInfo.InvariantCulture));

            Utility.SetResponseCachePolicy(new HttpCachePolicyElement(), new HttpResponseWrapper(response), defaultCacheability);
        }
        public static string GenerateUrl(string handlerUrl, string virtualPath,
                                         bool debug, string codeBufferVariableName, HttpCacheability cacheability,
                                         int cacheDuration)
        {
            Precondition.Defined(virtualPath,
                                 () => Error.ArgumentNull("virtualPath"));

            TemplateInfo info = new TemplateInfo();

            info.VirtualPath        = virtualPath;
            info.BufferVariableName = codeBufferVariableName;
            info.Cacheability       = cacheability;
            info.CacheDuration      = cacheDuration;
            info.Debug = debug;

            return(GenerateUrl(handlerUrl, info));
        }
        /// <summary>
        ///  Sets the http response parameters for status code, caching, and headers.
        /// </summary>
        private static void SetResponseParameters(HttpResponse response, HttpCacheability defaultCacheability, Entity annotation, byte[] data)
        {
            response.StatusCode  = (int)HttpStatusCode.OK;
            response.ContentType = annotation.GetAttributeValue <string>("mimetype");

            var contentDisposition = new StringBuilder("inline");

            AppendFilenameToContentDisposition(annotation, contentDisposition);

            response.AppendHeader("Content-Disposition", contentDisposition.ToString());
            response.AppendHeader("Content-Length", data.Length.ToString());

            var section = PortalCrmConfigurationManager.GetPortalCrmSection();
            var policy  = section.CachePolicy.Annotation;

            Utility.SetResponseCachePolicy(policy, response, defaultCacheability);
        }
Пример #33
0
 internal void Reset()
 {
     this._varyByContentEncodings.Reset();
     this._varyByHeaders.Reset();
     this._varyByParams.Reset();
     this._isModified          = false;
     this._hasSetCookieHeader  = false;
     this._noServerCaching     = false;
     this._cacheExtension      = null;
     this._noTransforms        = false;
     this._ignoreRangeRequests = false;
     this._varyByCustom        = null;
     this._cacheability        = HttpCacheability.Public | HttpCacheability.Private;
     this._noStore             = false;
     this._privateFields       = null;
     this._noCacheFields       = null;
     this._utcExpires          = DateTime.MinValue;
     this._isExpiresSet        = false;
     this._maxAge              = TimeSpan.Zero;
     this._isMaxAgeSet         = false;
     this._proxyMaxAge         = TimeSpan.Zero;
     this._isProxyMaxAgeSet    = false;
     this._slidingExpiration   = -1;
     this._slidingDelta        = TimeSpan.Zero;
     this._utcTimestampCreated = DateTime.MinValue;
     this._utcTimestampRequest = DateTime.MinValue;
     this._validUntilExpires   = -1;
     this._allowInHistory      = -1;
     this._revalidation        = HttpCacheRevalidation.None;
     this._utcLastModified     = DateTime.MinValue;
     this._isLastModifiedSet   = false;
     this._etag = null;
     this._generateLastModifiedFromFiles = false;
     this._generateEtagFromFiles         = false;
     this._validationCallbackInfo        = null;
     this._useCachedHeaders            = false;
     this._headerCacheControl          = null;
     this._headerPragma                = null;
     this._headerExpires               = null;
     this._headerLastModified          = null;
     this._headerEtag                  = null;
     this._headerVaryBy                = null;
     this._noMaxAgeInCacheControl      = false;
     this._hasUserProvidedDependencies = false;
     this._omitVaryStar                = -1;
 }
 internal HttpCachePolicySettings(bool isModified, System.Web.ValidationCallbackInfo[] validationCallbackInfo, bool hasSetCookieHeader, bool noServerCaching, string cacheExtension, bool noTransforms, bool ignoreRangeRequests, string[] varyByContentEncodings, string[] varyByHeaderValues, string[] varyByParamValues, string varyByCustom, HttpCacheability cacheability, bool noStore, string[] privateFields, string[] noCacheFields, DateTime utcExpires, bool isExpiresSet, TimeSpan maxAge, bool isMaxAgeSet, TimeSpan proxyMaxAge, bool isProxyMaxAgeSet, int slidingExpiration, TimeSpan slidingDelta, DateTime utcTimestampCreated, int validUntilExpires, int allowInHistory, HttpCacheRevalidation revalidation, DateTime utcLastModified, bool isLastModifiedSet, string etag, bool generateLastModifiedFromFiles, bool generateEtagFromFiles, int omitVaryStar, HttpResponseHeader headerCacheControl, HttpResponseHeader headerPragma, HttpResponseHeader headerExpires, HttpResponseHeader headerLastModified, HttpResponseHeader headerEtag, HttpResponseHeader headerVaryBy, bool hasUserProvidedDependencies)
 {
     this._isModified = isModified;
     this._validationCallbackInfo = validationCallbackInfo;
     this._hasSetCookieHeader = hasSetCookieHeader;
     this._noServerCaching = noServerCaching;
     this._cacheExtension = cacheExtension;
     this._noTransforms = noTransforms;
     this._ignoreRangeRequests = ignoreRangeRequests;
     this._varyByContentEncodings = varyByContentEncodings;
     this._varyByHeaderValues = varyByHeaderValues;
     this._varyByParamValues = varyByParamValues;
     this._varyByCustom = varyByCustom;
     this._cacheability = cacheability;
     this._noStore = noStore;
     this._privateFields = privateFields;
     this._noCacheFields = noCacheFields;
     this._utcExpires = utcExpires;
     this._isExpiresSet = isExpiresSet;
     this._maxAge = maxAge;
     this._isMaxAgeSet = isMaxAgeSet;
     this._proxyMaxAge = proxyMaxAge;
     this._isProxyMaxAgeSet = isProxyMaxAgeSet;
     this._slidingExpiration = slidingExpiration;
     this._slidingDelta = slidingDelta;
     this._utcTimestampCreated = utcTimestampCreated;
     this._validUntilExpires = validUntilExpires;
     this._allowInHistory = allowInHistory;
     this._revalidation = revalidation;
     this._utcLastModified = utcLastModified;
     this._isLastModifiedSet = isLastModifiedSet;
     this._etag = etag;
     this._generateLastModifiedFromFiles = generateLastModifiedFromFiles;
     this._generateEtagFromFiles = generateEtagFromFiles;
     this._omitVaryStar = omitVaryStar;
     this._headerCacheControl = headerCacheControl;
     this._headerPragma = headerPragma;
     this._headerExpires = headerExpires;
     this._headerLastModified = headerLastModified;
     this._headerEtag = headerEtag;
     this._headerVaryBy = headerVaryBy;
     this._hasUserProvidedDependencies = hasUserProvidedDependencies;
 }
Пример #35
0
        public static void OutputCache(this HttpResponseBase response,
                                       int numberOfSeconds,
                                       bool sliding = false,
                                       IEnumerable <string> varyByParams           = null,
                                       IEnumerable <string> varyByHeaders          = null,
                                       IEnumerable <string> varyByContentEncodings = null,
                                       HttpCacheability cacheability = HttpCacheability.Public)
        {
            HttpCachePolicyBase cache = response.Cache;

            var context = HttpContext.Current;

            cache.SetCacheability(cacheability);
            cache.SetExpires(context.Timestamp.AddSeconds(numberOfSeconds));
            cache.SetMaxAge(new TimeSpan(0, 0, numberOfSeconds));
            cache.SetValidUntilExpires(true);
            cache.SetLastModified(context.Timestamp);
            cache.SetSlidingExpiration(sliding);

            if (varyByParams != null)
            {
                foreach (var p in varyByParams)
                {
                    cache.VaryByParams[p] = true;
                }
            }

            if (varyByHeaders != null)
            {
                foreach (var headerName in varyByHeaders)
                {
                    cache.VaryByHeaders[headerName] = true;
                }
            }

            if (varyByContentEncodings != null)
            {
                foreach (var contentEncoding in varyByContentEncodings)
                {
                    cache.VaryByContentEncodings[contentEncoding] = true;
                }
            }
        }
Пример #36
0
        public void SetCacheability(HttpCacheability cacheability, string field)
        {
            if (field == null)
            {
                throw new ArgumentNullException("field");
            }

            if (cacheability != HttpCacheability.NoCache && cacheability != HttpCacheability.Private)
            {
                throw new ArgumentException("Must be NoCache or Private", "cacheability");
            }

            if (fields == null)
            {
                fields = new ArrayList();
            }

            fields.Add(new Pair(cacheability, field));
        }
 internal HttpCachePolicySettings(bool isModified, System.Web.ValidationCallbackInfo[] validationCallbackInfo, bool hasSetCookieHeader, bool noServerCaching, string cacheExtension, bool noTransforms, bool ignoreRangeRequests, string[] varyByContentEncodings, string[] varyByHeaderValues, string[] varyByParamValues, string varyByCustom, HttpCacheability cacheability, bool noStore, string[] privateFields, string[] noCacheFields, DateTime utcExpires, bool isExpiresSet, TimeSpan maxAge, bool isMaxAgeSet, TimeSpan proxyMaxAge, bool isProxyMaxAgeSet, int slidingExpiration, TimeSpan slidingDelta, DateTime utcTimestampCreated, int validUntilExpires, int allowInHistory, HttpCacheRevalidation revalidation, DateTime utcLastModified, bool isLastModifiedSet, string etag, bool generateLastModifiedFromFiles, bool generateEtagFromFiles, int omitVaryStar, HttpResponseHeader headerCacheControl, HttpResponseHeader headerPragma, HttpResponseHeader headerExpires, HttpResponseHeader headerLastModified, HttpResponseHeader headerEtag, HttpResponseHeader headerVaryBy, bool hasUserProvidedDependencies)
 {
     this._isModified             = isModified;
     this._validationCallbackInfo = validationCallbackInfo;
     this._hasSetCookieHeader     = hasSetCookieHeader;
     this._noServerCaching        = noServerCaching;
     this._cacheExtension         = cacheExtension;
     this._noTransforms           = noTransforms;
     this._ignoreRangeRequests    = ignoreRangeRequests;
     this._varyByContentEncodings = varyByContentEncodings;
     this._varyByHeaderValues     = varyByHeaderValues;
     this._varyByParamValues      = varyByParamValues;
     this._varyByCustom           = varyByCustom;
     this._cacheability           = cacheability;
     this._noStore             = noStore;
     this._privateFields       = privateFields;
     this._noCacheFields       = noCacheFields;
     this._utcExpires          = utcExpires;
     this._isExpiresSet        = isExpiresSet;
     this._maxAge              = maxAge;
     this._isMaxAgeSet         = isMaxAgeSet;
     this._proxyMaxAge         = proxyMaxAge;
     this._isProxyMaxAgeSet    = isProxyMaxAgeSet;
     this._slidingExpiration   = slidingExpiration;
     this._slidingDelta        = slidingDelta;
     this._utcTimestampCreated = utcTimestampCreated;
     this._validUntilExpires   = validUntilExpires;
     this._allowInHistory      = allowInHistory;
     this._revalidation        = revalidation;
     this._utcLastModified     = utcLastModified;
     this._isLastModifiedSet   = isLastModifiedSet;
     this._etag = etag;
     this._generateLastModifiedFromFiles = generateLastModifiedFromFiles;
     this._generateEtagFromFiles         = generateEtagFromFiles;
     this._omitVaryStar                = omitVaryStar;
     this._headerCacheControl          = headerCacheControl;
     this._headerPragma                = headerPragma;
     this._headerExpires               = headerExpires;
     this._headerLastModified          = headerLastModified;
     this._headerEtag                  = headerEtag;
     this._headerVaryBy                = headerVaryBy;
     this._hasUserProvidedDependencies = hasUserProvidedDependencies;
 }
Пример #38
0
        internal static void OutputCache(
            HttpContextBase httpContext,
            HttpCachePolicyBase cache,
            int numberOfSeconds,
            bool sliding,
            IEnumerable <string> varyByParams,
            IEnumerable <string> varyByHeaders,
            IEnumerable <string> varyByContentEncodings,
            HttpCacheability cacheability
            )
        {
            cache.SetCacheability(cacheability);
            cache.SetExpires(httpContext.Timestamp.AddSeconds(numberOfSeconds));
            cache.SetMaxAge(new TimeSpan(0, 0, numberOfSeconds));
            cache.SetValidUntilExpires(true);
            cache.SetLastModified(httpContext.Timestamp);
            cache.SetSlidingExpiration(sliding);

            if (varyByParams != null)
            {
                foreach (var p in varyByParams)
                {
                    cache.VaryByParams[p] = true;
                }
            }

            if (varyByHeaders != null)
            {
                foreach (var headerName in varyByHeaders)
                {
                    cache.VaryByHeaders[headerName] = true;
                }
            }

            if (varyByContentEncodings != null)
            {
                foreach (var contentEncoding in varyByContentEncodings)
                {
                    cache.VaryByContentEncodings[contentEncoding] = true;
                }
            }
        }
Пример #39
0
        internal static void OutputCache(HttpContextBase httpContext,
                                         HttpCachePolicyBase cache,
                                         int numberOfSeconds,
                                         bool sliding,
                                         IEnumerable<string> varyByParams,
                                         IEnumerable<string> varyByHeaders,
                                         IEnumerable<string> varyByContentEncodings,
                                         HttpCacheability cacheability)
        {
            cache.SetCacheability(cacheability);
            cache.SetExpires(httpContext.Timestamp.AddSeconds(numberOfSeconds));
            cache.SetMaxAge(new TimeSpan(0, 0, numberOfSeconds));
            cache.SetValidUntilExpires(true);
            cache.SetLastModified(httpContext.Timestamp);
            cache.SetSlidingExpiration(sliding);

            if (varyByParams != null)
            {
                foreach (var p in varyByParams)
                {
                    cache.VaryByParams[p] = true;
                }
            }

            if (varyByHeaders != null)
            {
                foreach (var headerName in varyByHeaders)
                {
                    cache.VaryByHeaders[headerName] = true;
                }
            }

            if (varyByContentEncodings != null)
            {
                foreach (var contentEncoding in varyByContentEncodings)
                {
                    cache.VaryByContentEncodings[contentEncoding] = true;
                }
            }
        }
Пример #40
0
        public static void OutputCache(this HttpResponseBase response, 
            int numberOfSeconds,
            bool sliding = false,
            IEnumerable<string> varyByParams = null,
            IEnumerable<string> varyByHeaders = null,
            IEnumerable<string> varyByContentEncodings = null,
            HttpCacheability cacheability = HttpCacheability.Public) {

            HttpCachePolicyBase cache = response.Cache;

            var context = HttpContext.Current;
            cache.SetCacheability(cacheability);
            cache.SetExpires(context.Timestamp.AddSeconds(numberOfSeconds));
            cache.SetMaxAge(new TimeSpan(0, 0, numberOfSeconds));
            cache.SetValidUntilExpires(true);
            cache.SetLastModified(context.Timestamp);
            cache.SetSlidingExpiration(sliding);

            if (varyByParams != null) {
                foreach (var p in varyByParams) {
                    cache.VaryByParams[p] = true;
                }
            }

            if (varyByHeaders != null) {
                foreach (var headerName in varyByHeaders) {
                    cache.VaryByHeaders[headerName] = true;
                }
            }

            if (varyByContentEncodings != null) {
                foreach (var contentEncoding in varyByContentEncodings) {
                    cache.VaryByContentEncodings[contentEncoding] = true;
                }
            }
        }
Пример #41
0
    /// <summary>
    /// 设置 cache-control 标头为 HttpCacheability 值之一
    /// </summary>
    /// <param name="cacheability">缓存可用性</param>
    public override void SetCacheability( HttpCacheability cacheability )
    {

      switch ( cacheability )
      {
        case HttpCacheability.NoCache:
        case HttpCacheability.Private:
        case HttpCacheability.Public:
          _cachePolicy.SetCacheability( cacheability );
          break;


        default:
          throw new InvalidOperationException();
      }

    }
 public HttpCacheAttribute()
 {
     _cacheability = HttpCacheability.Public;
     _revalidation = HttpCacheRevalidation.None;
 }
 public override void SetCacheability(HttpCacheability cacheability)
 {
     m_Cacheability = cacheability;
 }
        /*
         * Reset based on a cached response. Includes data needed to generate
         * header for a cached response.
         */
        internal void ResetFromHttpCachePolicySettings(
                HttpCachePolicySettings settings,
                DateTime                utcTimestampRequest) {

            int i, n;
            string[] fields;
            
            _utcTimestampRequest = utcTimestampRequest;

            _varyByContentEncodings.ResetFromContentEncodings(settings.VaryByContentEncodings);
            _varyByHeaders.ResetFromHeaders(settings.VaryByHeaders);                          
            _varyByParams.ResetFromParams(settings.VaryByParams);

            _isModified                       = settings.IsModified;                    
            _hasSetCookieHeader               = settings.hasSetCookieHeader;
            _noServerCaching                  = settings.NoServerCaching;               
            _cacheExtension                   = settings.CacheExtension;                
            _noTransforms                     = settings.NoTransforms;                  
            _ignoreRangeRequests              = settings.IgnoreRangeRequests;
            _varyByCustom                     = settings.VaryByCustom;
            _cacheability                     = settings.CacheabilityInternal;                  
            _noStore                          = settings.NoStore;
            _utcExpires                       = settings.UtcExpires;                       
            _isExpiresSet                     = settings.IsExpiresSet;                  
            _maxAge                           = settings.MaxAge;                        
            _isMaxAgeSet                      = settings.IsMaxAgeSet;                   
            _proxyMaxAge                      = settings.ProxyMaxAge;                   
            _isProxyMaxAgeSet                 = settings.IsProxyMaxAgeSet;              
            _slidingExpiration                = settings.SlidingExpirationInternal;             
            _slidingDelta                     = settings.SlidingDelta;
            _utcTimestampCreated              = settings.UtcTimestampCreated;
            _validUntilExpires                = settings.ValidUntilExpiresInternal;
            _allowInHistory                   = settings.AllowInHistoryInternal;
            _revalidation                     = settings.Revalidation;                  
            _utcLastModified                  = settings.UtcLastModified;                  
            _isLastModifiedSet                = settings.IsLastModifiedSet;             
            _etag                             = settings.ETag;                          
            _generateLastModifiedFromFiles    = settings.GenerateLastModifiedFromFiles; 
            _generateEtagFromFiles            = settings.GenerateEtagFromFiles;         
            _omitVaryStar                     = settings.OmitVaryStarInternal;
            _hasUserProvidedDependencies      = settings.HasUserProvidedDependencies;

            _useCachedHeaders = true;
            _headerCacheControl = settings.HeaderCacheControl;
            _headerPragma = settings.HeaderPragma;        
            _headerExpires = settings.HeaderExpires;       
            _headerLastModified = settings.HeaderLastModified;  
            _headerEtag = settings.HeaderEtag;          
            _headerVaryBy = settings.HeaderVaryBy;        

            _noMaxAgeInCacheControl = false;

            fields = settings.PrivateFields;
            if (fields != null) {
                _privateFields = new HttpDictionary();
                for (i = 0, n = fields.Length; i < n; i++) {
                    _privateFields.SetValue(fields[i], fields[i]);
                }
            }

            fields = settings.NoCacheFields;
            if (fields != null) {
                _noCacheFields = new HttpDictionary();
                for (i = 0, n = fields.Length; i < n; i++) {
                    _noCacheFields.SetValue(fields[i], fields[i]);
                }
            }

            if (settings.ValidationCallbackInfo != null) {
                _validationCallbackInfo = new ArrayList();
                for (i = 0, n = settings.ValidationCallbackInfo.Length; i < n; i++) {
                    _validationCallbackInfo.Add(new ValidationCallbackInfo(
                            settings.ValidationCallbackInfo[i].handler,
                            settings.ValidationCallbackInfo[i].data));
                }
            }
        }
 public HttpCacheAttribute(HttpCacheability cacheability)
 {
     _cacheability = cacheability;
     _revalidation = HttpCacheRevalidation.None;
 }
 public virtual new void SetCacheability (HttpCacheability cacheability, string field)
 {
 }
Пример #47
0
 public override void SetCacheability(HttpCacheability cacheability, string field)
 {
     this._httpCachePolicy.SetCacheability(cacheability, field);
 }
		public override void SetCacheability (HttpCacheability cacheability, string field)
		{
			w.SetCacheability (cacheability, field);
		}
        /*
         * Cacheability policy
         * 
         * Cache-Control: public | private[=1#field] | no-cache[=1#field] | no-store
         */

        /// <devdoc>
        ///    <para>Sets the Cache-Control header to one of the values of 
        ///       HttpCacheability. This is used to enable the Cache-Control: public, private, and no-cache directives.</para>
        /// </devdoc>
        public void SetCacheability(HttpCacheability cacheability) {
            if ((int) cacheability < (int) HttpCacheabilityLimits.MinValue || 
                (int) HttpCacheabilityLimits.MaxValue < (int) cacheability) {

                throw new ArgumentOutOfRangeException("cacheability");
            }

            if (s_cacheabilityValues[(int)cacheability] < s_cacheabilityValues[(int)_cacheability]) {
                Dirtied();
                _cacheability = cacheability;
            }
        }
 public HttpCacheAttribute(HttpCacheability cacheability,
     HttpCacheRevalidation revalidation)
 {
     _cacheability = cacheability;
     _revalidation = revalidation;
 }
		public override void SetCacheability (HttpCacheability cacheability)
		{
			w.SetCacheability (cacheability);
		}
 public virtual void SetCacheability(HttpCacheability cacheability, string field) {
     throw new NotImplementedException();
 }
Пример #53
0
		public void SetCacheability (HttpCacheability cacheability, string field)
		{
			if (field == null)
				throw new ArgumentNullException ("field");

			if (cacheability != HttpCacheability.NoCache && cacheability != HttpCacheability.Private)
				throw new ArgumentException ("Must be NoCache or Private", "cacheability");

			if (fields == null)
				fields = new ArrayList ();

			fields.Add (new Pair (cacheability, field));
		}
Пример #54
0
		//
		// This one now allows the full range of Cacheabilities.
		//
		public void SetCacheability (HttpCacheability cacheability)
		{
			if (cacheability < HttpCacheability.NoCache || cacheability > HttpCacheability.ServerAndPrivate)
				throw new ArgumentOutOfRangeException ("cacheability");

			if (Cacheability > 0 && cacheability > Cacheability)
				return;

			Cacheability = cacheability;
		}
Пример #55
0
 /// <summary>
 /// 设置 cache-control 标头为 HttpCacheability 值之一
 /// </summary>
 /// <param name="cacheability">缓存可用性</param>
 public override void SetCacheability( HttpCacheability cacheability )
 {
   switch ( cacheability )
   {
     case HttpCacheability.NoCache:
     case HttpCacheability.Private:
     case HttpCacheability.Public:
       _cacheability = cacheability;
       break;
     default:
       throw new ArgumentException( "cacheability", "不受支持的 Cacheablity 值" );
   }
 }
        /// <devdoc>
        ///    <para>Sets the Cache-Control header to one of the values of HttpCacheability in 
        ///       conjunction with a field-level exclusion directive.</para>
        /// </devdoc>
        public void SetCacheability(HttpCacheability cacheability, String field) {
            if (field == null) {
                throw new ArgumentNullException("field");
            }

            switch (cacheability) {
                case HttpCacheability.Private:
                    if (_privateFields == null) {
                        _privateFields = new HttpDictionary();
                    }

                    _privateFields.SetValue(field, field);

                    break;

                case HttpCacheability.NoCache:
                    if (_noCacheFields == null) {
                        _noCacheFields = new HttpDictionary();
                    }

                    _noCacheFields.SetValue(field, field);

                    break;

                default:
                    throw new ArgumentException(
                            SR.GetString(SR.Cacheability_for_field_must_be_private_or_nocache),
                            "cacheability");
            }

            Dirtied();
        }
Пример #57
0
 /// <summary>
 /// 设置 cache-control 标头为 HttpCacheability 值之一
 /// </summary>
 /// <param name="cacheability">缓存可用性</param>
 public abstract void SetCacheability( HttpCacheability cacheability );
        /*
         * Restore original values
         */
        internal void Reset() {
            _varyByContentEncodings.Reset();
            _varyByHeaders.Reset();
            _varyByParams.Reset();

            _isModified = false;
            _hasSetCookieHeader = false;
            _noServerCaching = false;
            _cacheExtension = null;
            _noTransforms = false;
            _ignoreRangeRequests = false;
            _varyByCustom = null;
            _cacheability = (HttpCacheability) (int) HttpCacheabilityLimits.None;
            _noStore = false;
            _privateFields = null;
            _noCacheFields = null;
            _utcExpires = DateTime.MinValue;
            _isExpiresSet = false;
            _maxAge = TimeSpan.Zero;
            _isMaxAgeSet = false;
            _proxyMaxAge = TimeSpan.Zero;
            _isProxyMaxAgeSet = false;
            _slidingExpiration = -1;
            _slidingDelta = TimeSpan.Zero;
            _utcTimestampCreated = DateTime.MinValue;
            _utcTimestampRequest = DateTime.MinValue;
            _validUntilExpires = -1;
            _allowInHistory = -1;
            _revalidation = HttpCacheRevalidation.None;
            _utcLastModified = DateTime.MinValue;
            _isLastModifiedSet = false;
            _etag = null;

            _generateLastModifiedFromFiles = false; 
            _generateEtagFromFiles = false;         
            _validationCallbackInfo = null;       
        
            _useCachedHeaders = false;
            _headerCacheControl = null;
            _headerPragma = null;        
            _headerExpires = null;       
            _headerLastModified = null;  
            _headerEtag = null;          
            _headerVaryBy = null;       

            _noMaxAgeInCacheControl = false;

            _hasUserProvidedDependencies = false;

            _omitVaryStar = -1;
        }
 public virtual new void SetCacheability (HttpCacheability cacheability)
 {
 }
Пример #60
0
 public override void SetCacheability(HttpCacheability cacheability)
 {
     this._httpCachePolicy.SetCacheability(cacheability);
 }