Re: cache_serials and non-cacheable plugins

"messju mohr" <[email protected]> Thu, 1 Sep 2005 11:48:21 +0200
Newsgroups gmane.comp.php.smarty.devel
Message-ID <20050901094820.GA13992@dune>
On Thu, Sep 01, 2005 at 12:39:20AM +0200, Nichlas Löfdahl wrote:
> Hello!
> 
> I'm having some problems, which seems to be (without deeper knowledge of Smarty internals) originating from how cache_serials are generated (md5(uniqid())).
> 
> I have a couple of webservers. The compiled templates are stored locally on the webservers.  The smarty cache-files are stored on a shared storage.

yes, that is a problem regarding cache_serials.
 
> The templates in question are componized, made of parts which are cached seperatly (by using a second instance of smarty and doing $cache_smarty->fetch() and then $smarty->assign() the result to the main template).

that should not be a problem.
 
> I also have a function plugin registered as non-cachable. When the cached part of the template is shown it also shows a string like " {nocache:d41d8cd98f00b204e9800998ecf8427e#0} ". Obviously it seems like Smarty cannot replace the nocache-part with the appropiate function.
> 
> Any ideas how to solve this? It would be good if the serials wasn't timebased (uniqid()) because the clock of the different webservers in a cluster is never completely synched.

You could try to stick the _cache_serial to something shared between
the servers, like this:

Index: Smarty_Compiler.class.php
===================================================================
RCS file: /repository/smarty/libs/Smarty_Compiler.class.php,v
retrieving revision 1.371
diff -u -r1.371 Smarty_Compiler.class.php
--- Smarty_Compiler.class.php   5 Aug 2005 20:53:04 -0000       1.371
+++ Smarty_Compiler.class.php   1 Sep 2005 09:38:16 -0000
@@ -2213,7 +2213,7 @@
         $_cacheable = !isset($this->_plugins[$type][$name]) || $this->_plugins[$type][$name][4];
         if ($_cacheable
             || 0<$this->_cacheable_state++) return '';
-        if (!isset($this->_cache_serial)) $this->_cache_serial = md5(uniqid('Smarty'));
+        if (!isset($this->_cache_serial)) $this->_cache_serial = md5($this->_current_file);
         $_ret = 'if ($this->caching && !$this->_cache_including) { echo \'{nocache:'
             . $this->_cache_serial . '#' . $this->_nocache_count
             . '}\';}';


So that all servers compile the same templates with the same cache_serials.

I'm not 100% sure if this has any negative side-effects, but i cannot
think of any.

greetings
messju

> /Nichlas

-- 
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php