I have done some digging as to what might have happened:
The cache clearing is initiated by Yoast in the wordpress-seo/inc/class-wpseo-utils.php file, while it’s creating the schema, and occurs when the company_logo_id in the Yoast settings is “0”. This results in the cache being cleared on most page visits when the page schema is generated.
I see there’s fallback code that tries to retrieves an ID based off the image attachment URL, if the image_id isn’t set:
$image_id = WPSEO_Options::get( $setting . '_id', false );
if ( ! $image_id ) {
$image = WPSEO_Options::get( $setting, false );
if ( $image ) {
// There is not an option to put a URL in an image field in the settings anymore, only to upload it through the media manager.
// This means an attachment always exists, so doing this is only needed once.
$image_id = self::get_attachment_by_url( $image );
WPSEO_Options::set( $setting . '_id', $image_id );
}
}
In this case the image had been cropped in the media library and I’m taking a guess the custom get_attachment_by_url function couldn’t find the image ID based off the old URL. Although the original image was still in the uploads folder. Re-adding the image loaded the new cropped version and the correct ID was added.
Unfortunately I can’t replicate the ID being set to 0 on a test site, with a cropped image. Perhaps the ID was added and set to 0 on an older Yoast version, or something else generates that ID after the image has been added?
It sounds like the OP had a similar issue, since removing the old image fixed the issue.
Here is a backtrace if it helps:
wp_cache_clear_cache() ../wordpress-seo/inc/class-wpseo-utils.php:441
clear_cache() ../wp-includes/class-wp-hook.php:305
apply_filters() ../wp-includes/class-wp-hook.php:327
do_action() ../wp-includes/plugin.php:470
do_action() ../wp-includes/option.php:521
update_option() ../wordpress-seo/inc/options/class-wpseo-options.php:507
save_option() ../wordpress-seo/inc/options/class-wpseo-options.php:311
set() ../wordpress-seo/inc/class-wpseo-image-utils.php:459
get_attachment_id_from_settings() ../wordpress-seo/src/helpers/image-helper.php:331
get_attachment_id_from_settings() ../wordpress-seo/src/context/meta-tags-context.php:318
generate_company_logo_id() ../wordpress-seo/src/presentations/abstract-presentation.php:64