コード例 #1
0
 /// <summary>
 /// Insert object to underlying cache
 /// </summary>
 /// <param name="key">key used to reference the object</param>
 /// <param name="value">object</param>
 /// <param name="dependency">dependency</param>
 /// <param name="absoluteExpiration">absolute time expiration</param>
 /// <param name="slidingExpiration">sliding time expiration</param>
 public void Insert(string key, object value, CacheDependency dependency, DateTime absoluteExpiration, TimeSpan slidingExpiration)
 {
     if (!this._useNoSync)
     {
         this._cache.Insert(key, value, dependency, absoluteExpiration, slidingExpiration, CacheItemPriority.Default);
     }
     else
     {
         this._cache.Insert(key, TagUtil.CreateTaggedCacheItem(value, dependency, absoluteExpiration, slidingExpiration, CacheItemPriority.Default));
         this._noSyncLocalCache.Insert(key, TagUtil.CreateTaggedCacheItem(value), dependency, absoluteExpiration, slidingExpiration, CacheItemPriority.Default);
     }
 }
コード例 #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);
            }
        }