Create caching_client_attach_object function to reduce the amount of duplicated code.