public void RefreshCachedExecuted ( DbConnection connection , string storeProcedureName ) { var dataSource = connection.DataSource; var dataBase = connection.Database; var key = $"{connection.DataSource}-{connection.Database}-{storeProcedureName}".ToUpper(); ExecutingInfo executingInfo = null; if ( _dictionary .TryGetValue ( key , out executingInfo ) ) { executingInfo .RecentExecutedTime = DateTime.Now; } }
GetCachedParameters ( string connectionString , string storeProcedureName , bool includeReturnValueParameter = false ) { ExecutingInfo GetExecutingInfo() { var nameIndexedParameters = GetNameIndexedDefinitionParameters ( connectionString , storeProcedureName , includeReturnValueParameter ); var _executingInfo = new ExecutingInfo() { DbParameters = nameIndexedParameters , RecentExecutedTime = DateTime.Now }; return(_executingInfo); } DbConnection connection = new TDbConnection(); connection.ConnectionString = connectionString; var key = $"{connection.DataSource}-{connection.Database}-{storeProcedureName}".ToUpper(); var add = false; var executingInfo = _dictionary .GetOrAdd ( key , (x) => { var r = GetExecutingInfo(); add = true; return(r); } ); var result = executingInfo.DbParameters; if (!add) { if (CachedParametersDefinitionExpiredInSeconds > 0) { var locker = executingInfo .Locker; locker .LockIf ( () => { var diffSeconds = DateTimeHelper .SecondsDiffNow ( executingInfo .RecentExecutedTime ); var r = ( diffSeconds > CachedParametersDefinitionExpiredInSeconds ); return(r); } , () => { executingInfo .DbParameters = GetNameIndexedDefinitionParameters ( connectionString , storeProcedureName , includeReturnValueParameter ); } ); } } return(result); }