Skip to content

Instantly share code, notes, and snippets.

@mohfahrul
Last active March 31, 2022 07:12
Show Gist options
  • Save mohfahrul/3917281dacbac6f9aa0de923d21c22f9 to your computer and use it in GitHub Desktop.
Save mohfahrul/3917281dacbac6f9aa0de923d21c22f9 to your computer and use it in GitHub Desktop.
Flush Cache - Helper Magento
<?php
namespace Icube\Training\Helper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\App\Cache\TypeListInterface;
use Magento\Framework\App\Cache\Frontend\Pool;
class Kuli extends \Magento\Framework\App\Helper\AbstractHelper
{
protected $cacheTypeList;
protected $cacheFrontendPool;
public function __construct(
TypeListInterface $cacheTypeList,
Pool $cacheFrontendPool
)
{
$this->_cacheTypeList = $cacheTypeList;
$this->_cacheFrontendPool = $cacheFrontendPool;
}
public function flushCache(){
// for cache database just cacheFrontend worked
// $types = [
// 'config',
// 'layout',
// 'block_html',
// 'collections',
// 'reflection',
// 'db_ddl',
// 'eav',
// 'config_integration',
// 'config_integration_api',
// 'full_page',
// 'translate',
// 'config_webservice'
// ];
// foreach ($types as $type){
// $this->_cacheTypeList->cleanType($type);
// }
foreach ($this->_cacheFrontendPool as $cacheFrontend){
$cacheFrontend->getBackend()->clean();
}
}
}
<?php
namespace Icube\Training\Block;
class Use extends \Magento\Framework\View\Element\Template
{
protected $helperKuli;
public function __construct(
\Icube\Training\Helper\Kuli $helperKuli
)
{
$this->_helperKuli = $helperKuli;
}
public function execute( ) {
$this->_helperKuli->flushCache();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment