You can add plugin to override getCacheLifetime()
method in path
app\code\VendorName\ModuleName\etc\di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Vendor\Demo\Block\Menu">
<plugin name="override_cachelifetime" type="VendorName\ModuleName\Plugin\Block\MenuPlugin" />
</type>
</config>
<?php
namespace VendoreName\ModuleName\Plugin;
class MenuPlugin
{
public function afterGetCacheLifetime(\Vendor\Demo\Block\Menu $subject, $oldLifetime)
{
return null; // return the new value here
}
}