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

ClearCache() based on expiry date

 
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 -> Smarty 3
View previous topic :: View next topic  
Author Message
bluejester
Smarty Regular


Joined: 26 Apr 2012
Posts: 55

PostPosted: Thu May 23, 2013 3:13 pm    Post subject: ClearCache() based on expiry date Reply with quote

Hello,

I'm using Smarty 3.1.13 and use the Smarty Cache very much for an application that requires huge db resources.

Depending the user's request, I will SetCacheLifetime from 1 month to 1 year. It works well.

The point is that the application is very used and the cache directory is filled with thousands and thousands of cached files (I set a different CacheId depending on the user's request), resulting as a performance issue.

To clear the cache of files older than 1 month, I can do this :
$smarty->clearAllCache(3600 * 24 * 30);

My problem is that it also destroys every cache file where CacheLifeTime has been set to 2 months, 6 months, 1 year, etc.

Is there any way to clean the cache by some method like $smarty->clearExpiredCache() ? I actually want the clear method to be based to the cache expiration date instead of the cache generation date.

Thanks,
Ben
Back to top
View user's profile Send private message Visit poster's website
U.Tews
Administrator


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

PostPosted: Thu May 23, 2013 8:38 pm    Post subject: Reply with quote

That's a good point.

A preliminary solution is to modify smarty_internal_cachresource_file.php starting at line 212 to
Code:

                    // expired ?
                    preg_match('#\'cache_lifetime\' =>\s*(\d*)#', file_get_contents($_file), $match);
                    if ($_time < (@filemtime($_file) + $match[1])) {
                        continue;
                    }
                    $_count += @unlink((string) $_file) ? 1 : 0;


This patch will delete all expired cache files based on the stored life_time.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Sun May 26, 2013 10:52 am    Post subject: Reply with quote

The general solution is now in the SVN trunk and will later be included in 3.1.14

An expire_time of -1 in clearCache() and clearAllCache() will delete outdated cache files
by their individual cache_lifetime used at creation.
Back to top
View user's profile Send private message
Aristophan
Smarty Regular


Joined: 10 Jan 2011
Posts: 96

PostPosted: Mon May 27, 2013 9:33 am    Post subject: Reply with quote

Can you estimate when 3.1.14 will be released, Uwe?
Back to top
View user's profile Send private message
bluejester
Smarty Regular


Joined: 26 Apr 2012
Posts: 55

PostPosted: Mon May 27, 2013 12:37 pm    Post subject: Reply with quote

In 3 words : you are great.

Thanks !
Ben
Back to top
View user's profile Send private message Visit poster's website
Aristophan
Smarty Regular


Joined: 10 Jan 2011
Posts: 96

PostPosted: Fri May 31, 2013 9:19 am    Post subject: Reply with quote

Aristophan wrote:
Can you estimate when 3.1.14 will be released, Uwe?

Please forgive! Just to get this into focus again...
Back to top
View user's profile Send private message
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 -> Smarty 3 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