Keep same logic as in master branch, except attach cache after Stat is successful.