[Skip to main content](#vessel-content)

#   Module and page caching for better performance

##

- **[mtense](/forum/user/10417-mtense "View mtense's Profile")**
- [![mtense's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/10417-mtense "View mtense's Profile") Topic Author
- [ Offline](/forum/user/10417-mtense)

Less More

- Posts: 36
- Thank you received: 6
-
-

12 years 8 months ago [\#148625](#148625) by [mtense](/forum/user/10417-mtense "View mtense's Profile")  *[Module and page caching for better performance](/forum/26-product-category-display/866711-module-and-page-caching-for-better-performance#148625 "I help run a hikashop store with over 4000 products and over 5000 categories. We have modules for best selling ever, best selling lately and recently added on the home page and on many other pages....")* was created by *[mtense](/forum/user/10417-mtense "View mtense's Profile")*

I help run a hikashop store with over 4000 products and over 5000 categories. We have modules for best selling ever, best selling lately and recently added on the home page and on many other pages. While these modules don't need to be updated often, joomla module caching controls are primitive. When users are logged in, caching is disabled, so our return customers were getting the worst of bad performance.

I solved our speed problems by writing custom modules with caching support. The module contents are written to disk once a day (or course that is configurable) and then simply echoed the rest of the time. I accomplished this using the Sourcerer plugin. If there is interest in how I did this, I can provide more details or maybe package up an example.

Oh, and as the subject states, I did this for a couple pages with many (1000+) categories also.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84NjY3MTEtbW9kdWxlLWFuZC1wYWdlLWNhY2hpbmctZm9yLWJldHRlci1wZXJmb3JtYW5jZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86584
- Thank you received: 14325
-
-

12 years 8 months ago [\#148652](#148652) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Module and page caching for better performance](/forum/26-product-category-display/866711-module-and-page-caching-for-better-performance#148652 "I help run a hikashop store with over 4000 products and over 5000 categories. We have modules for best selling ever, best selling lately and recently added on the home page and on many other pages....")*

That's interesting. Thank you for sharing your experience !

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84NjY3MTEtbW9kdWxlLWFuZC1wYWdlLWNhY2hpbmctZm9yLWJldHRlci1wZXJmb3JtYW5jZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[listsubscriber](/forum/user/16705-listsubscriber "View listsubscriber's Profile")**
- [![listsubscriber's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/16705-listsubscriber "View listsubscriber's Profile")
- [ Offline](/forum/user/16705-listsubscriber)

Less More

- Posts: 31
- Thank you received: 0
-
-

12 years 7 months ago [\#151138](#151138) by [listsubscriber](/forum/user/16705-listsubscriber "View listsubscriber's Profile")  Replied by *[listsubscriber](/forum/user/16705-listsubscriber "View listsubscriber's Profile")* on topic *[Module and page caching for better performance](/forum/26-product-category-display/866711-module-and-page-caching-for-better-performance#151138 "I help run a hikashop store with over 4000 products and over 5000 categories. We have modules for best selling ever, best selling lately and recently added on the home page and on many other pages....")*

Please provide details or package your stuff as a component/plugin. We would LOVE to use it! We have noticed pretty bad performance with many categories. We tried another caching component but it didn't work well with yootheme templates.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84NjY3MTEtbW9kdWxlLWFuZC1wYWdlLWNhY2hpbmctZm9yLWJldHRlci1wZXJmb3JtYW5jZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[mtense](/forum/user/10417-mtense "View mtense's Profile")**
- [![mtense's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/10417-mtense "View mtense's Profile") Topic Author
- [ Offline](/forum/user/10417-mtense)

Less More

- Posts: 36
- Thank you received: 6
-
-

12 years 7 months ago [\#151436](#151436) by [mtense](/forum/user/10417-mtense "View mtense's Profile")  Replied by *[mtense](/forum/user/10417-mtense "View mtense's Profile")* on topic *[Module and page caching for better performance](/forum/26-product-category-display/866711-module-and-page-caching-for-better-performance#151436 "I help run a hikashop store with over 4000 products and over 5000 categories. We have modules for best selling ever, best selling lately and recently added on the home page and on many other pages....")*

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
Code:

function display($tpl = null,$params=array()){ $this-&gt;paramBase = HIKASHOP_COMPONENT.'.'.$this-&gt;getName(); $function = $this-&gt;getLayout(); $this-&gt;params = $params; $config =&amp; hikashop_config(); $this-&gt;assignRef('config',$config); $module = hikashop_get('helper.module'); $module-&gt;initialize($this); $this-&gt;paramBase.='_'.$this-&gt;params-&gt;get('main_div_name'); $cid = $id = JRequest::getInt("cid",$this-&gt;params-&gt;get('selectparentlisting')); if ($cid == "12" &#124;&#124; $cid == "35") { $cache_id = "hika" . $cid; if (!ds_use_cache($cache_id ,strtotime('-1 hour'))) { ob_start(); if(method_exists($this,$function)) $this-&gt;$function(); parent::display($tpl); $html = ob_get_clean(); echo ($html); ds_create_cache($cache_id, $html); } } else { if(method_exists($this,$function)) $this-&gt;$function(); parent::display($tpl); } }

The utility code looks like this
Code:

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 &lt; $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); } }

The following user(s) said Thank You: [Xavier](/forum/user/4105-xavier "View Xavier's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84NjY3MTEtbW9kdWxlLWFuZC1wYWdlLWNhY2hpbmctZm9yLWJldHRlci1wZXJmb3JtYW5jZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.071 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
