Пример #1
0
        /// <summary>
        /// Occurs when ASP.NET completes an authorization event to let the caching modules
        /// serve requests from the cache, bypassing execution of the event handler (for
        /// example, a page or an XML Web service).
        /// </summary>
        /// <param name="source"></param>
        /// <param name="ea"></param>
        private void ResolveRequestCache(object o, EventArgs args)
        {
            HttpApplication application  = (HttpApplication)o;
            HttpContext     context      = application.Context;
            string          key          = context.Request.FilePath.ToLower();
            PageSettings    pageSettings = _reader.GetPageSettings(key);

            if (pageSettings == null)
            {
                return;
            }
            if (this._cache == null)
            {
                return;
            }
            if (!pageSettings.CachingEnabled)
            {
                return;
            }
            if (!pageSettings.Get && context.Request.HttpMethod == "GET")
            {
                return;
            }
            else if (!pageSettings.Post && context.Request.HttpMethod == "POST")
            {
                return;
            }

            try
            {
                string varyingKey = key + this.CreateVaryingKey(pageSettings, context);
                NItem  item       = this._cache.Get(varyingKey, pageSettings) as NItem;

                if (item == null)
                {
                    NFilter nFilter = new NFilter(context.Response.Filter);
                    context.Response.Filter = nFilter;

                    context.Items[_filterKey] = nFilter;
                    return;
                }

                context.Response.ClearContent();
                context.Response.BinaryWrite(item.Buffer);

                application.CompleteRequest();
            }
            catch (Exception e)
            {
                RaiseException(e);
            }
        }
Пример #2
0
        /// <summary>
        /// Occurs when ASP.NET finishes executing an event handler in order to let caching
        /// modules store responses that will be used to serve subsequent requests from
        /// the cache.
        /// </summary>
        /// <param name="o"></param>
        /// <param name="args"></param>
        private void UpdateRequestCache(object o, EventArgs args)
        {
            HttpApplication application  = (HttpApplication)o;
            HttpContext     context      = application.Context;
            string          key          = context.Request.FilePath.ToLower();
            PageSettings    pageSettings = _reader.GetPageSettings(key);

            if (pageSettings == null)
            {
                return;
            }
            if (this._cache == null)
            {
                return;
            }
            if (!pageSettings.CachingEnabled)
            {
                return;
            }
            if (!pageSettings.Get && context.Request.HttpMethod == "GET")
            {
                return;
            }
            else if (!pageSettings.Post && context.Request.HttpMethod == "POST")
            {
                return;
            }

            try
            {
                if (context.Response.StatusCode == 200)
                {
                    NFilter nFilter = context.Items[_filterKey] as NFilter;
                    if (nFilter != null)
                    {
                        context.Items.Remove(_filterKey);

                        NItem item = new NItem(PageHash(key), nFilter.ToArray());
                        this._cache.Insert(key + TagUtil.CreateTaggedCacheItem(this.CreateVaryingKey(pageSettings, context)), item, null, DateTime.Now.AddSeconds(pageSettings.ExpirationTime), Alachisoft.NCache.Web.Caching.Cache.NoSlidingExpiration);
                    }
                }
            }
            catch (Exception e)
            {
                RaiseException(e);
            }
        }