Cache a Smarty block function

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
pmw
New Member
New Member
Posts: 6
Joined: Thu Feb 16, 2012 2:15 pm

Cache a Smarty block function

Post by pmw »

I use GeSHi as syntax highlighter. But GeSHi is very slow, so I want to cache my Smarty block function and not to call this function for every page visitor. How can I make Smarty to cache the result of my block function?

Code: Select all

<?php
  require_once(dirname(__FILE__) .'/geshi/geshi.php');

  function smarty_block_code($params, $content, &$smarty)
  {
    if (isset($content) && isset($params['lang'])) {
      $geshi = new GeSHi($content, $params['lang']);
      $geshi->enable_classes(true);
      $geshi->enable_keyword_links(false);
      $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
      return $geshi->parse_code();
    }
  }
  ?>
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Cache a Smarty block function

Post by calguy1000 »

In CMSMS 1.11, plugins named smarty_xxxx are cachable by default. However the site developer must enable smarty caching for the site, and enable caching on the appropriate page(s).

functions named smarty_cms_xxxx will not be cachable.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
pmw
New Member
New Member
Posts: 6
Joined: Thu Feb 16, 2012 2:15 pm

Re: Cache a Smarty block function

Post by pmw »

I tried to upgrade to CMSMS 1.11.4, but the caching doesn't work. I have enabled "Enable Smarty Caching" and have cleared the template cache. But CMSMS still doesn't cache my block function :(

The name of my function is "smarty_block_code". So it should be cached by default.
pmw
New Member
New Member
Posts: 6
Joined: Thu Feb 16, 2012 2:15 pm

Re: Cache a Smarty block function

Post by pmw »

I have submitted the problem as bug: http://dev.cmsmadesimple.org/bug/view/8918
Post Reply

Return to “Developers Discussion”