You'd just call the cache() method on the app object (a local $this->app or $this->app(), XF::app() if you have to). It returns null if there's no cache enabled.
I would like to be able to see in my add-on if this has been entered into the config.php. If in my add-on I add the following:
PHP:
$cacheEnabled = \XF::app()->cache->enabled;
I get this error message:
ErrorException: Undefined property: Doctrine\Common\Cache\VoidCache::$enabled in src/addons/Andy/InsertAttachmentAll/Pub/Controller/InsertAttachmentAll.php at line 20
So what would be the correct PHP code to see if the cache is enabled?