Check if `$cache_needs_updating` is set

Fixes `Notice: Undefined variable: cache_needs_updating`