Welcome Guest | Login

Clearing Cache via Cron

I'm trying to clear my rails cache via cron.

I've found a perl script online that I configured to delete all files in my cache directory:
$BACKUP_DIR = "/home/mysite/apps/myapp/current/mycache";

# Read directory (ignoring . and ..)
opendir(DIR,"$BACKUP_DIR") || die "opendir $BACKUP_DIR failed";
@files = grep(!/^\.\.?$/,readdir(DIR));
closedir(DIR);

# delete all files in directory
foreach $f (@files)
{
     system("rm $BACKUP_DIR/$f");
}
In my crontab I have the following:
50 19 * * * /usr/bin/perl /home/mysite/apps/myapp/clear_cache.pl
I've changed the permissions on the script, and directory to 777 for testing purposes to rule that out.

I don't get any email with an error, but my script doesn't clear out the directory.  If I run the perl script by itself, it works fine.  Any ideas?  Thanks for any help.

2008-05-15 07:58 PM

I've edited your perlscript to give it a shebangline as below.
#/usr/bin/perl  
The script is now clearing the files inside
/home/user/apps/user/current/cachedir as I've verified it running it every minute. Please check it back now.

2008-05-15 08:21 PM

Perfect!  Thanks so much Varun.  It's working great.  I'd recommend this to anybody using page caching for a daily cache of pages that gets cleared out every midnight.

2008-05-15 09:11 PM

My page caching is working in that pages are being stored to the cache.  I've asked changes be made to the httpd.conf to reroute to this new cache directory.  However my pages aren't being served from the cache.  Is there anything else that needs to be done?  I tried restarting mongrel to see if that would help, as that restarts apache, correct?  Thanks for any ideas.

2008-05-17 09:26 PM

Restarting mongrel doesn't restart apache - but you shouldn't need to do this for page caching. Rails has expires_page actions to clear the cache for you so you could call it when a page updates.  If you're on mongrel then you shouldn't need to change anything in your httpd.conf file - you can set your cache folder in your environment.rb or production.rb

2008-05-18 01:00 AM

MN MLS - Buy/Sell Real Estate in Minnesota
Hi William, I've been looking into this issue more because in my development enviroment I can cache pages, but Mongrel doesn't want to cooperate and serve the cached pages.  Same thing happens in production.  I came across a blog posting and this patch, which seem to address why mongrel isn't serving the cached pages.
http://rubyforge.org/tracker/index.php?func=detail&aid=17713&group_id=1306&atid=5147

Is it possible to see the httpd.conf section or be sent it via email?  I'm not sure the httpd.conf is correctly pointed to 'dancache' directory as mongrel/rails is still processing all requests in production.

2008-05-26 08:28 PM

mongrel/rails processes all requests in production mode since you start mongrel processes in production environment on the server.

mongrel_rails start -e production -p <port> -d

>>Is it possible to see the httpd.conf section or be sent it via >>email?

Post us a support request, we will paste the main vhost entries for the required domain.

2008-05-26 10:34 PM

Regards,
Rahul

Hello Guest! In order to post you must be an active client with us, please log in or sign up today!