refactored logic for when we need to update the cache