clear_ref_cache(): extract two new functions