Esempio n. 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);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets all expiration records
        /// </summary>
        private static System.Xml.XmlDocument GetFileExpirations(ref SQLOptions o)
        {
            System.Xml.XmlDocument doc;
            object obj;

            o.WriteToLog("attempt loading cache_expirations from memory");
            obj = SQLMemoryCache.GetFromMemoryCache("cache_expirations", ref o);
            if (obj == null)
            {
                o.WriteToLog("attempt loading cache_expirations from file");
                string FileName = GetCacheFilePath("cache_expirations");

                if (System.IO.File.Exists(FileName))
                {
                    doc = new System.Xml.XmlDocument();
                    doc.Load(FileName);
                    o.WriteToLog("saving cache_expirations to memory");
                    SQLMemoryCache.AddToMemoryCache("cache_expirations", doc, ref o, DateTime.Now.AddDays(30), false);
                    return(doc);
                }
                else
                {
                    o.WriteToLog("creating file and saving cache_expirations to memory");
                    doc = CreateFileExpirationsFile(null, ref o);
                    SQLMemoryCache.AddToMemoryCache("cache_expirations", doc, ref o, DateTime.Now.AddDays(30), false);
                    return(doc);
                }
            }
            else
            {
                return((System.Xml.XmlDocument)obj);
            }
        }
Esempio n. 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);
        }
Esempio n. 4
0
 /// <summary>
 /// Saves expiration records
 /// </summary>
 public static void SaveFileExpirations(System.Xml.XmlDocument doc, ref SQLOptions o)
 {
     SQLMemoryCache.AddToMemoryCache("cache_expirations", doc, ref o, DateTime.Now.AddDays(30), false);
     CreateFileExpirationsFile(doc, ref o);
 }