You can flush cache programmatically in your controller, So don't need to clear cache manually and don't need to disable cache for particular block.
Please check the below code for cache clear
1.Add below lines after namespace
use Magento\Framework\App\PageCache\Version;
use Magento\Framework\App\Cache\TypeListInterface;
use Magento\Framework\App\Cache\Frontend\Pool;
2.Define variables
protected $cacheTypeList;
protected $cacheFrontendPool;
- Add params to construct method
/**
* Cache clear
*
* @param TypeListInterface $cacheTypeList
* @param Pool $cacheFrontendPool
*/
public function __construct(
TypeListInterface $cacheTypeList,
Pool $cacheFrontendPool
) {
$this->cacheTypeList = $cacheTypeList;
$this->cacheFrontendPool = $cacheFrontendPool;
}
- The Last step for clearing the cache in your execute method
$_types = [
'config',
'block_html',
'full_page',
'config_webservice'
];
foreach ($_types as $type) {
$this->cacheTypeList->cleanType($type);
}
foreach ($this->cacheFrontendPool as $cacheFrontend) {
$cacheFrontend->getBackend()->clean();
}
You can check here
Sometimes I also faced this type of issue, at this time I use this way.
I hope it's an alternative way without disabling the cache and manually clearing the cache, Your submitted form data will show in the frontend.
Thanks