Optimize the code inside AR::QueryCache middleware
#32414

bogdan wants to merge bogdan:query-cache-optimization into rails:master

We do not currently have an analysis of these two commits