示例#1
0
        /// <summary>
        /// Adds an object to the SQLCache
        /// </summary>
        public static void AddToCache(string Key, object Obj, ref SQLOptions o)
        {
            if (System.Web.HttpContext.Current == null)
            {
                throw new Exception("Caching is not available outside of web context");
            }

            //if(log == null)
            //log = new TextLog();

            if (o.DoFileCache)
            {
                try
                {
                    SQLFileCache.AddToFileCache(Key, Obj, ref o);
                }
                catch (Exception ex)
                {
                    o.WriteToLog("Error trying to save to SQL FileCache: " + ex.Message);
                    General.Debugging.Report.SendError("Error trying to save to SQL FileCache", ex);
                }
            }

            if (o.DoMemoryCache)
            {
                SQLMemoryCache.AddToMemoryCache(Key, Obj, ref o);
            }
        }
示例#2
0
        //COMMENTED OUT
        #region AddToCache Overloads

/*
 *              private static void AddToCache(string Key, object Obj)
 *              {
 *                      int intTimeoutMinutes;
 *                      try
 *                      {
 *                              intTimeoutMinutes = Convert.ToInt32(GlobalConfiguration.GlobalSettings["sqlhelper_data_cache_timeout"]);
 *                      }
 *                      catch
 *                      {
 *                              intTimeoutMinutes = 240;
 *                      }
 *
 *                      AddToCache(Key, Obj, DateTime.Now.AddMinutes(intTimeoutMinutes));
 *              }
 */
        #endregion
        //END COMMENT

        #region Misc
        /// <summary>
        /// OnCacheRemoveCallback
        /// </summary>
        public static void OnCacheRemoveCallback(string Key, object Obj, CacheItemRemovedReason R)
        {
            //THIS METHOD RUNS WHEN A CACHED DATASET EXPIRES
            if (System.Web.HttpContext.Current != null)
            {
                _intCacheCount--;
                SQLFileCache.DeleteCacheFile(Key);
            }
        }
示例#3
0
        /// <summary>
        /// Retrieves an object from the SQLCache
        /// </summary>
        public static object GetFromCache(string Key, ref SQLOptions o)
        {
            object obj = null;

            if (System.Web.HttpContext.Current == null)
            {
                throw new Exception("Caching is not available outside of web context");
            }

            if (o.DoMemoryCache)
            {
                obj = SQLMemoryCache.GetFromMemoryCache(Key, ref o);
            }

            if (obj != null)
            {
                //General.Debug.Trace("Got from memory cache");
                o.WriteToLog("Retrieved from memory cache");
            }

            if (obj == null && o.DoFileCache)
            {
                try
                {
                    obj = SQLFileCache.GetFromFileCache(Key, ref o);
                    if (obj != null && o.DoMemoryCache)
                    {
                        SQLMemoryCache.AddToMemoryCache(Key, obj, ref o);
                    }
                }
                catch (Exception ex)
                {
                    obj = null;
                    o.WriteToLog("Error trying to load SQL FileCache: " + ex.Message);
                    General.Debugging.Report.SendError("Error trying to load SQL FileCache", ex);
                }
                if (obj != null)
                {
                    General.Debug.Trace("Got from file cache");
                    o.WriteToLog("Retrieved from file cache");
                }
            }

            return(obj);
        }
示例#4
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++;
        }