Fix two issues with the SQL cache (see #6507)