So, for the modules I basically re-created the best selling and most recent ones in php. I use sourcerer within customHTML module to load my custom php. I call functions to check the cache and generate the module output if necessary. So, it is not a general solution at this point. I contacted the author of Advanced Module Manager, but he was not interested in added caching support. He said there are too many places it would not work. I told him that on the places it would work that it can be a life saver, but to no alas. I am considering creating something like loadposition plugin that would support caching. Not sure when I will get around to it.
For the caching category listings, I added code directly to view.html.php
function display($tpl = null,$params=array()){
$this->paramBase = HIKASHOP_COMPONENT.'.'.$this->getName();
$function = $this->getLayout();
$this->params = $params;
$config =& hikashop_config();
$this->assignRef('config',$config);
$module = hikashop_get('helper.module');
$module->initialize($this);
$this->paramBase.='_'.$this->params->get('main_div_name');
$cid = $id = JRequest::getInt("cid",$this->params->get('selectparentlisting'));
if ($cid == "12" || $cid == "35")
{
$cache_id = "hika" . $cid;
if (!ds_use_cache($cache_id ,strtotime('-1 hour')))
{
ob_start();
if(method_exists($this,$function)) $this->$function();
parent::display($tpl);
$html = ob_get_clean();
echo ($html);
ds_create_cache($cache_id, $html);
}
}
else
{
if(method_exists($this,$function)) $this->$function();
parent::display($tpl);
}
}
The utility code looks like this
function ds_use_cache($cache_id, $ts=0) {
$file = DS_CACHE.$cache_id;
if(file_exists($file)){
// and the file is readable
if(is_readable($file)){
$stale = false;
$filets = filemtime($file);
if ($ts) {
if ($filets < $ts) {
$stale = true;
}
}
else if (date('Ymd', $filets) != date('Ymd')) {
$stale = true;
}
if ($stale == false) {
// open the file for reading
if($fp=@fopen($file,'r')){
if(flock($fp, LOCK_SH))
fpassthru($fp);
flock($fp, LOCK_UN);
fclose($fp);
return true;
}
fclose($fp);
}
}
}
return false;
}
function ds_create_cache($cache_id, $html)
{
$file = DS_CACHE.$cache_id;
if (file_exists($file)) {
$fp=@fopen($file,'r+');
} else {
$fp=@fopen($file,'w');
}
if ($fp) {
if(flock($fp, LOCK_EX)) {
ftruncate($fp, 0);
fwrite($fp,$html);
flock($fp, LOCK_UN);
}
fclose($fp);
}
}