Magneto Tutorial – Clear Full Page Cache via Cron

Magneto Tutorial – Clear Full Page Cache via Cron

Hey Friends

In Today’s tutorial we are showing How you can clear your magento’s Full Page Cache using cron

First of all create a Module as below


create a file registration.php


Create a module.xml under app/code/NameSpace/FpcRefreshCache/etc folder

<?xml version="1.0"?>
<config xmlns:xsi=""
<module name="NameSpace_FpcRefreshCache" setup_version="1.0.0" schema_version="0.0.1">

Create File NameSpace/FpcRefreshCache/Cron/ClearCache.php

namespace NameSpace\AutoRefreshCache\Cron;
use Magento\Framework\App\Cache\Manager;
use Magento\Framework\Event\ManagerInterface;
use Magento\PageCache\Model\Cache\Type as PageCacheType;
use Psr\Log\LoggerInterface as Logger;
class ClearCache
     * @var ManagerInterface
protected $eventManager;
     * @var Logger
protected $logger;
     * @var Manager
private $cacheManager;
     * ClearCache constructor.
     * @param ManagerInterface $eventManager
     * @param Logger $logger
     * @param Manager $cacheManager

public function __construct(
ManagerInterface $eventManager,
        Logger $logger,
        Manager $cacheManager

) {
$this->eventManager = $eventManager;
$this->logger = $logger;
$this->cacheManager = $cacheManager;
     *  Clear the cache on a time interval to Fix the add to cart issue
public function execute()
  $this->logger->info('Cache Cleaned - '.PageCacheType::TYPE_IDENTIFIER);
}//end class

Create a file crontab.xml

<group id="default">
 <job name="namespace_fpcrefreshcache_cron" instance="NameSpace\FpcRefreshCache\Cron\ClearCache" method="execute">
 <schedule>0 */4 * * *</schedule>

Hope You like our this solution! Please vist again.

Subscribe to our newsletter

Leave a Reply
Your email address will not be published. *