C# - can I cache a GameObject script component in another script?

I’m making some AI and I’m using this line a lot:

GetComponentInParent();

I know it’s bad practice t call this too often, and I’d like to cache it if possible.
There is a good chance if there are multiple game objects interacting at once, it may get called a dozen times.

Normally I cache components, however, I’m not sure how to do this with a script? or if it’s even possible?
I’ve tried this: Component parentScript = GetComponentInParent();
however, later on, when I try to get public variables like: parentScript.health, it doesn’t pick it up.

Does anyone know if it’s possible to cache a script component? (Or at the very least, link up variables some how?)

You can get the component with the generic version, if you return a type component it will only have the Component type methods and properties/fields available. So.

//... snip
private AIGameObjectScript aigo; // cached version in script, just a field

// Start or where ever makes sense.
void SomeMethod()
{  
    aigo = GetComponentInParent<AIGameObjectScript>(); // The generic call that get the first AIGameObjectScript type component from the parent.
}

To repeat myself, getting the component type doesn’t give the type you need(unless it does, but you stated it doesn’t) You could cast it but you might miss the target.