pre_get_posts for exclude category

$caid is unknown inside the function, unless declared global.

$caid = '-1';
function exclude_category( $query ) {
    global $caid;
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'cat', $caid );
    }
}
add_action( 'pre_get_posts', 'exclude_category' );

// Edit
Do you need the variable outside the function at all? If not, just move it inside the function, then you can ommit the global.

PHP: Variable scope