private TResult ExecuteSqlRequest() { TResult commandResult; using (SqlConnection sqlConnection = new SqlConnection(this.ConnectionString)) { using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlConnection.Open(); this.CommandBody(sqlCommand); sqlConnection.Close(); commandResult = this.GetCommandResult(sqlCommand); if (commandResult != null) { this.CacheDependency = CacheDependencyResolver.GetCachedDataDependencies(base.StoredProcedureName); this.CacheItemPriority = CacheDependencyResolver.GetCacheItemPriority(base.StoredProcedureName); if (this.CacheDependency == null) { Logger.WarnFormat(LogMessages.SqlDacs.SqlCommands.CacheDependencyNotFound, new object[] { base.StoredProcedureName }); } else { MlcSlcCache.InsertItemInCache <TResult>(this.CacheKey, commandResult, this.CacheDependency, this.SlidingExpiration, this.CacheItemPriority); return(commandResult); } } } } return(commandResult); }
public override void Execute() { if (!ConfigurationManager.Instance.IsEnabledDbCache) { base.Execute(); return; } try { IEnumerable <string> freeCacheDependencies = CacheDependencyResolver.GetFreeCacheDependencies(base.StoredProcedureName); if (freeCacheDependencies == null) { Logger.WarnFormat(LogMessages.SqlDacs.SqlCommands.FreeCacheDependencyNotFound, new object[] { base.StoredProcedureName }); } else { this.CacheKeyPrefixes = freeCacheDependencies.Select <string, string>(new Func <string, string>(MlcSlcCache.GetCacheKeyPrefix)).ToArray <string>(); MlcSlcCache.RemoveItemsFromCache(this.CacheKeyPrefixes); } using (SqlConnection sqlConnection = new SqlConnection(this.ConnectionString)) { using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlConnection.Open(); this.CommandBody(sqlCommand); sqlConnection.Close(); } } } catch (Exception exception) { Logger.Error(LogMessages.SqlDacs.SqlCommands.CommandExecutionError, exception); throw; } }
public override void Execute() { if (!ConfigurationManager.Instance.IsEnabledDbCache) { base.Execute(); return; } TResult itemFromCache = MlcSlcCache.GetItemFromCache <TResult>(this.CacheKey); if (itemFromCache != null) { this.IsDataFromCache = true; } else { MlcSlcCache.LockKey(this.CacheKey); try { try { itemFromCache = MlcSlcCache.GetItemFromCache <TResult>(this.CacheKey); if (itemFromCache != null) { this.IsDataFromCache = true; } else { itemFromCache = this.ExecuteSqlRequest(); } } catch (Exception exception) { Logger.Error(LogMessages.SqlDacs.SqlCommands.CommandExecutionError, exception); throw; } } finally { MlcSlcCache.UnlockKey(this.CacheKey); } } base.CommandResult = itemFromCache; }
protected static string GetCacheKey(params string[] args) { return(MlcSlcCache.GetCacheKey(args)); }