Azavea.Open.DAO.SQL.DbCommandCache.Return C# (CSharp) Method

Return() public method

Returns a command to the cache when it is no longer used, allowing another call to reuse it. This method is thread-safe.
public Return ( string sql, IDbConnection conn, IDbCommand cmd ) : void
sql string
conn IDbConnection
cmd IDbCommand
return void
        public void Return(string sql, IDbConnection conn, IDbCommand cmd)
        {
            StringBuilder keyBuilder = DbCaches.StringBuilders.Get();
            keyBuilder.Append(sql);
            keyBuilder.Append(conn.ConnectionString);
            string key = keyBuilder.ToString();

            // Save the time for reporting purposes.
            Chronometer.EndTiming(key);

            lock (_cache)
            {
                if (!_cache.ContainsKey(key))
                {
                    // Make sure we don't keep some random set of values for the params.
                    cmd.Parameters.Clear();
                    // It may have been used on a transaction, so clear that out.
                    cmd.Transaction = null;
                    // No command for this key, go ahead and cache it.
                    _cache[key] = cmd;
                } // else just discard this one, our cache is tolerant of sloppy usage.
            }
            DbCaches.StringBuilders.Return(keyBuilder);
        }
DbCommandCache