private static void PutInCache(string key, SfCommand cmd) { if (HttpContext.Current != null) HttpContext.Current.Cache.Add(key, cmd, new CacheDependency(new string[] { _customPath, _commonPath, _qsPath }), Cache.NoAbsoluteExpiration, TimeSpan.FromHours(1), CacheItemPriority.Normal, new CacheItemRemovedCallback(RemovedCallback)); }
private bool GetFromQueryStore(string obj, string query, out SfCommand cmd) { obj = obj.ToLower(); query = query.ToLower(); string key = obj + "/" + query; string sql = ""; if (GetFromCache(key, out cmd)) return cmd != null && !cmd.IsEmpty(); XmlElement el = ReadFile(_customPath, obj, query); bool bCustom = false; if (el == null) { el = ReadFile(_qsPath, obj, query); if (el == null) el = ReadFile(_commonPath, obj, query); } else bCustom = true; if (el != null) sql = el.InnerText; cmd = new SfCommand(this, sql); PutInCache(key, cmd); Logger.Info("Inserita in cache la query " + (bCustom ? "CUSTOM " : "") + "per " + key + " = " + sql); return !cmd.IsEmpty(); }
private static bool GetFromCache(string key, out SfCommand cmd) { cmd = HttpContext.Current == null? null: (SfCommand)HttpContext.Current.Cache[key]; return cmd != null; }