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

max_cache_memory

 
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 -> Feature Requests
View previous topic :: View next topic  
Author Message
atu
Smarty Regular


Joined: 18 Apr 2003
Posts: 51
Location: Luxembourg

PostPosted: Tue Aug 26, 2003 5:17 pm    Post subject: max_cache_memory Reply with quote

I propose the following script to prevent abuse of different cache id's to fill up server memory. This script count the size of every template output and add this value to a variable. If the size of this variable > 1000000 the cache is deleted.
Ref.: http://lists.php.net/article.php?group=php.smarty.general&article=10031

Code:

/*
   cache_memory.php contains a single variable "$cache_memory=0;"
*/

   $output = $smarty->fetch( 'index.tpl', $_cache_id);

   if(!$smarty->is_cached( 'index.tpl', $_cache_id ))
   {
      include 'configs/cache_memory.php';

      $mem = $cache_memory + strlen($output);

      if($mem > 1000000)
      {
          $smarty->clear_all_cache();
          $mem = 0;
      }
      $_mem_content = "<?php \$cache_memory={$mem}; ?>";

      $_fp = fopen('configs/cache_memory.php',"w");
      $_action = fwrite($_fp,$_mem_content);
      fclose($_fp);
  }



This could be a usefull feature to add to smarty;
$smarty->max_cache_memory = 1000000;

Armand
Back to top
View user's profile Send private message Visit poster's website
andre
Smarty Pro


Joined: 23 Apr 2003
Posts: 164
Location: Karlsruhe, Germany

PostPosted: Wed Aug 27, 2003 5:50 am    Post subject: Reply with quote

Very nice idea. But I would enhance my Smarty class and overwrite the fetch() method to do this stuff for me. Then no changes to the existing templates will be needed.
Back to top
View user's profile Send private message
atu
Smarty Regular


Joined: 18 Apr 2003
Posts: 51
Location: Luxembourg

PostPosted: Wed Aug 27, 2003 9:06 am    Post subject: templates? Reply with quote

Hi,
I cant see the relation with changes in templates?!?

Quote:
Then no changes to the existing templates will be needed.
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Aug 27, 2003 9:09 am    Post subject: Reply with quote

Perhaps andre meant that then it would be transparent and you wouldn't have to implement it for every fetch() / display() of a template Question
Back to top
View user's profile Send private message
andre
Smarty Pro


Joined: 23 Apr 2003
Posts: 164
Location: Karlsruhe, Germany

PostPosted: Wed Aug 27, 2003 9:20 am    Post subject: Reply with quote

Yeah, thanks boots, andre meant this. Wink
Too early and too much alcohol yesterday... forget about it. Embarassed
Back to top
View user's profile Send private message
atu
Smarty Regular


Joined: 18 Apr 2003
Posts: 51
Location: Luxembourg

PostPosted: Wed Aug 27, 2003 5:07 pm    Post subject: The worst case Reply with quote

Yes, I can understand now what andre mean. It depends of how your system is build up. If you call differnt templates through index.php?tpl=xxx you only need one fetch or dislplay for all templates.

But independent of this, abusing of different cacheid's of non existing pages is a problem of all sites that use smarty. So including a feature like:
$smarty->max_cache_memory = 1000000;
could prevent from the worst case. It could be a simpel and fast feature. On some systems, especially on cms systems, it's a lot of work to test if an url is what is seems to be.
Back to top
View user's profile Send private message Visit poster's website
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 -> Feature Requests 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