Is there a way to check if a game object has a cached component?

I’m trying to apply a basic motion to different game objects. One has an animator component and the other doesn’t. The problem is that I want to cache GetComponent() so it’s not called every frame. So far, the only solution I have is to check to see if the Animator is null, but it would still be called every frame:

private void Awake()
{
     animator = GetComponent<Animator>();
}

private void Update()
{
     MoveHorizontal();
}

private void MoveHorizontal()
{
     if(direction = 1)
     {
          direction = -1;

          if(animator != null)
          {
               animator.SetTrigger("Start");
          }
     }

 if(direction = -1)
     {
          direction = 1;

          if(animator != null)
          {
               animator.SetTrigger("End");
          }
     }
}

Any solutions to do this so it only has to get the component once?

Simple solution. I just created a bool that is set to true for anything that I want animated. Snippet:

private bool isAnimated;

private void MoveHorizontal()
{
     if (direction = 1)
     {
          direction = -1;

          if(isAnimated)
               animator.SetTrigger("Start");
     }
}