cache_sql is now thread-safe

If a thread execute a SELECT query while an UPDATE query is performed in another thread, the `has_key?` returns `true` and then the `@query_cache[sql]` could be nil if the @query_cache is cleared. (This happen with Capybara. See http://blog.zedroot.org/capybara-and-parallel_test-undefined-method-%60collect-for-nilnilclass/).