Whenever I change the time intervals for ex: from ‘three_days’ to ‘five_minutes’ or from ‘five_minutes’ to ‘fifteen_minutes’, the cron is running with earlier frequency and not the updated one.
Because you only reschedule the event if it does not exist:
if ( ! wp_next_scheduled( 'bd_cron_cache' ) ) {
// schedule
}
…which will always be false
once you initially schedule the event. Instead, check the stored task’s schedule against the value you actually want it to be:
if ( wp_get_schedule( 'bd_cron_cache' ) !== 'twenty_minutes' ) {
// Above statement will also be true if NO schedule exists, so here we check and unschedule if required
if ( $time = wp_next_schedule( 'bd_cron_cache' ) ) {
wp_unschedule_event( $time, 'bd_cron_cache' );
}
wp_schedule_event( time(), 'bd_cron_cache', 'twenty_minutes' );
}