Example #1
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);
        }