Example #1
0
        /// <summary>
        /// Add to SQL Memory Cache
        /// </summary>
        public static void AddToMemoryCache(string Key, object Obj, ref SQLOptions o)
        {
            if (System.Web.HttpContext.Current == null)
            {
                throw new Exception("Caching is not available outside of web context");
            }
            System.Web.Caching.Cache GlobalCache = System.Web.HttpContext.Current.Cache;

            o.WriteToLog("adding object to memory cache... " + Key + "...Expire=" + o.Expiration.ToString() + "...FileDependency=" + o.DoFileCache);
            System.Web.Caching.CacheDependency dep;
            if (o.DoFileCache)
            {
                dep = new CacheDependency(SQLFileCache.GetCacheFilePath(Key));
            }
            else
            {
                dep = null;
            }
            CacheItemRemovedCallback OnCacheRemove = new CacheItemRemovedCallback(OnCacheRemoveCallback);

            GlobalCache.Add("SQLHelper:" + Key, Obj, dep, o.Expiration, Cache.NoSlidingExpiration, CacheItemPriority.Normal, OnCacheRemove);
            _intCacheCount++;
        }