|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
bluejester Smarty Regular
Joined: 26 Apr 2012 Posts: 55
|
Posted: Thu May 23, 2013 3:13 pm Post subject: ClearCache() based on expiry date |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu May 23, 2013 8:38 pm Post subject: |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun May 26, 2013 10:52 am Post subject: |
|
|
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 |
|
Aristophan Smarty Regular
Joined: 10 Jan 2011 Posts: 96
|
Posted: Mon May 27, 2013 9:33 am Post subject: |
|
|
Can you estimate when 3.1.14 will be released, Uwe? |
|
Back to top |
|
bluejester Smarty Regular
Joined: 26 Apr 2012 Posts: 55
|
Posted: Mon May 27, 2013 12:37 pm Post subject: |
|
|
In 3 words : you are great.
Thanks !
Ben |
|
Back to top |
|
Aristophan Smarty Regular
Joined: 10 Jan 2011 Posts: 96
|
Posted: Fri May 31, 2013 9:19 am Post subject: |
|
|
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 |
|
|
|
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
|