Caution: this post was published in 2019 and may contain information, techniques or code examples that are no longer current. Please double-check official documentation and modern best practices before using anything from this article.

This is a stand alone script which can be called to refresh the cache in Magento 2

<?php

use Magento\Framework\App\Bootstrap;
include('app/bootstrap.php'); // Update as required, this line will work if placed in the Magento Root Directory
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();

?><div style='top:45%; position:absolute; width:75%; text-align:center; color:#666; font-weight:bold; font-size:1.8em; '><?php

try{
    $_cacheTypeList = $objectManager->create('Magento\Framework\App\Cache\TypeListInterface');
    $_cacheFrontendPool = $objectManager->create('Magento\Framework\App\Cache\Frontend\Pool');
    $types = array('config','layout','block_html','collections','reflection','db_ddl','eav','config_integration','config_integration_api','full_page','translate','config_webservice');
    foreach ($types as $type) {
        $_cacheTypeList->cleanType($type);
    }
    foreach ($_cacheFrontendPool as $cacheFrontend) {
        $cacheFrontend->getBackend()->clean();
    }
    ?><span style='color:green'>&#9679; Success. </span> The cache has been cleared. <?php
}catch(Exception $e){
    ?><span style='color:red'>&#9679; Error. </span><?php
    echo $msg = 'Error : '.$e->getMessage();die();
}

The script hooks into Bootstrap to generate a unique instance without needing to hook into Magento itself. The System will loop through all the cache types specified on line 13. If you have any custom modules that also require a cache, add it into this list.