/// <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); } }
/// <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); }