Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

cache_handler_func with mysql

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
schildi
Smarty Regular


Joined: 11 Mar 2005
Posts: 81

PostPosted: Sun Jun 15, 2008 1:59 pm    Post subject: cache_handler_func with mysql Reply with quote

hello,

i tried to test the cache_handler_func with mysql, but it does not work as expected. i used the example from http://www.smarty.net/manual/de/section.template.cache.handler.func.php

when i use it within my app it always seems to generate a new cache-file instead of delivering an existing one. maybe the example doesnt include that functionality?

i would be happy, if somebody could help me.
maybe you have a working mysql-implementation?

i want to use mysql, because the file-system-related caching begins to slow down response times from about 15.000 cache-files on (no folders, cause i dont want to disable set safe_mode). file-system is xfs.

i assume a database can handle large number of files better (maybe up to 100.000 - 500.000 files?).

thanks for your help in advance!
Back to top
View user's profile Send private message Send e-mail
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Jun 15, 2008 3:19 pm    Post subject: Reply with quote

I am not sure is caching in a mysql database will have a better performance.

I have had same problem because I wanted to cache pages for thousands of products. I have solved the problem by generating a cache_id from a product id as follow (using subdirs):

Code:
function get_cache_id ($product_id)
{
       $md5 = md5($product_id);
        return substr($md5, 0, 2) . '|' . substr($md5, 2, 2) . '|' .substr($md5, 4, 2).'|'.$product_id;
}


It did provide good performance in my case.

But I can see no reasion why the cache handler should not work if all caching parameters are set correcty. Are you sure that you have force_compile = false? Why are you assuming that always a new cache file is being generated?
Back to top
View user's profile Send private message
schildi
Smarty Regular


Joined: 11 Mar 2005
Posts: 81

PostPosted: Sun Jun 15, 2008 8:54 pm    Post subject: Reply with quote

i hope i will have a better performance. i should try it at least.

i do generate cache_id's by using md5 and the requested url. i include request vars to have the ability to save every page than can be generated.
i dont cache sites, that are "extremly" dynamic atm, cause the file-system cant manage 20.-30.000 cached sites satisfyingly anymore. it really slowed down the whole application some day.

but i want to cache as much as possible pages, because the building of my pages is comparatively complex.

your '|' in the cache-id causes smarty to split the string-parts into single folders? but .. in my case it wont help, i think atm.

i implemented the smarty-example, and didnt changed any other code. although smarty never returned a cached template. i tested that.
i dont know where to start, cause i dont know how smarty works.

maybe the example is too old or something?

i really need hints :/
Back to top
View user's profile Send private message Send e-mail
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Jun 15, 2008 9:59 pm    Post subject: Reply with quote

I did test the cache handler and found two typo errors...

It must be $cache_content not $cache_contents.

Code:
   case 'read':

      // Cache aus der Datenbank lesen
      $results = mysql_query("select CacheContents from CACHE_PAGES where CacheID='$CacheID'");
      if(!$results) {
     $smarty_obj->_trigger_error_msg("cache_handler: query failed.");
      }
      $row = mysql_fetch_array($results,MYSQL_ASSOC);
     
      if($use_gzip && function_exists("gzuncompress")) {
     $cache_content = gzuncompress($row["CacheContents"]);
      } else {
     $cache_content = $row["CacheContents"];
      }
      $return = $results;
      break;
Back to top
View user's profile Send private message
schildi
Smarty Regular


Joined: 11 Mar 2005
Posts: 81

PostPosted: Mon Jun 16, 2008 8:14 am    Post subject: Reply with quote

yihaww!
works now! thanks!

didn't thought of typo errors!
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP