Aimy H1 Heading: Context: com_content.article

Schedule Cache Cleaning with a Cron Job

Here is the relevant transcript for this video:

cache clean with cron jobHey there, Joomla fans! Tim Davis here. Thanks for tuning in to Maintenance Monday here, the live stream on the Basic Joomla Tutorials channel.

Today's topic is how to empty the Joomla cache without logging in to the administrator area of your site.

I’ve chosen this topic today because of something that happened recently. I was in church on Sunday and had my phone in airplane mode so it wouldn't ring and interrupt the service. At about 1:30 when I was done talking to people, I put the phone back on and got notification that the main Cybersalt.org was down on my server. I knew the problem was probably that one of the temporary files went to make a folder, but the folder already existed. Now I don't know what the cause of this problem is, but all I had to do was log in to the site and empty the cache. Once I did that the site came back up and that error was gone off the site.

I knew that there's a way for me to set up a schedule so that the cache is emptied every now and then. That's what I will show you how to set up on your site today. Once this is set up, it'll just take care of itself. My site was down for an hour and a half. Had I set it to empty the cache every hour, it would have been down for an hour and then it would have been fixed and kept going.

Let's check out how to do that using Regular Labs Cache Cleaner.

Begin by going to RegularLabs.com, find the Cache Cleaner, and download the free version. If you don't know how to install that, then go down to the videos and there's a tutorial on how to download and install it. (You might even recognize the voice of the person talking on that video.)

So here we are on my basicjoomla.com site. We'll look in the back-end at Components and Regular Labs Extension Manager which you can also install from the Regular Labs site, or you could go to Extensions and Plug-ins and go to Cache Cleaner, or filter the title of that plug-in to find it quickly. The great thing about the Regular Labs Extension Manager is I can go down here to Cache Cleaner, I can click on the system plug-in and it will open up right at the plug-in here in the back end of the site.

I'm going to show you three ways to set this up so that you don't have to log-in to the admin area of your site.

The first way is to create a “Frontend secret URL” and as we scroll down here in this first tab of the plug-in you'll see you have to put in a front end secret word. I've put in, "clean me." Now when I go to www. the domain address of this site which is basicjoomla.com/freejoomla (that's the folder that I've put it in), when I go to that “/index.php?cleancache=cleanme” URL, then it will dump the cache in the backend of the site.

To demonstrate that, let's just go to a tab here that shows that homepage. Here we have the URL of the page: “/index.php?cleancache=cleanme”. Now watch. As we hit enter on that URL we will see a message pop up saying that the cache is being cleaned - 127,000.96 kilobytes - so just over a meg. Now I have a window open here which is the file manager on the web hosting account for this site, and you will see that I have it in freejoomla.com/cache. So, I'm looking at the cache file of this Joomla install. You'll see that right now the last time the cache was emptied 8:23 tonight, but because we just went to that URL with that secret word at the end of it I can reload this, and you'll see now it's all renewed at 8:42 p.m. which is the time we just did it.

So that's one of the methods to empty the cache without having to login. Basically, you could make a shortcut for this URL in your browser and you could have it to just do a drop down on your mobile phone or whatever. Whenever you need to empty the cache, then you could just bring up that bookmark.

Now another way to empty the cache is to put “&break =1” after your secret word. What that's going to do is cause the cache to be cleaned without calling for your page.

Now here is an advantage. If you're keeping track of the traffic to your site using Google Analytics or some other tool you don't want to be constantly adding hits to the pages because that would register a call to this page and why mess up your stats and your graphs. This method, of putting “&break=1” at the end, is a way to prevent the whole page called; it's quicker and again you preserve the purity of your analytics.

So you'll see that when we go to this longer URL and hit enter, we'll get a message that the cache has been cleaned. When we go back to the cache folder using our file manager in the hosting account, we can reload, and we'll see that now lots has been wiped out. That’s because using the other method, with the secret word only, empties the cache but then makes a page for you to view and that reloads the cache. It will be the most current view of what you're working on, but again this isn't so much for use when you're working on your site but rather when you need to empty the cache remotely.

So that's two methods and now I want to tell you about the third method which really fits in with the title of a Maintenance Monday. This is how to empty the cache with a cron job.

If you go to the Regular Labs site and look at Cache Cleaner, click on the tutorial link and you'll see the many things you can do with the free version, and what's included in the paid version. Scroll down to the very bottom and you'll come to this section that talks about cron jobs. Here is the code that you want to use to create a cron job on your server, in your hosting account. This code will run in the background at a specific time interval that you set and it will run the clean cache “mysecret&break=1”, the my secret being the secret word you choose when you create that cron job in the backend.

Using this method you don't even have to worry about calling it from a URL and if you want your cache emptied every hour of everything so everything works all together then it'll just happen throughout the night while you're sleeping or while you're working or when your phone's off in church. The cron job will take care of that problem. You simply get that code and make a cron job. In fact, let's do that now.

I am in cPanel for this basicJoomla.com/freeJoomla site, and I've already gone to the cron tabs. I search for cron tabs in cPanel and add a new cron job. Now over here on my other screen, I have opened notepad and already have the URL that I need to run this on my site for this particular Joomla install: wget -q -O /dev/null (that just keeps output from being emailed to you every time this runs), and then you put the URL that is going to be run by wget. Basically, your servers are going to try and get the page at this URL, and when this code is run your cache will be emptied in the background. So, we're going to copy that code (and make the adjustments as you need to for your site) and put it in the command line.

Before I hit "Add New Cron Job" I have to say how often I want it to run. In this setup of cPanel on Cybersalt Hosting, I'm going to say once per minute for now, just to see that it's working and see the time changing on the folders that are empty, but then later I'm going to select once per hour. Once I select once per minute that's going to put asterisk stars in everything. I just click "Add New Cron Job".

Now it is successfully completed, and every minute every hour every day every month every weekday it's going to run that link and empty the cache on my site.

Alright, so let's go back to file manager and we will see that the last time when we refreshed this folder it was 8:44, and we'll look down here at the time. It's 8:50 when I reload this page. Now we see the last time that that folder was created is 8:50 p.m., so we know that the cron job is working. This has been a bit of involved, a bit longer than usual, but this really does solve the problem that I was having with wondering if when I'm away from my site or if I turn my phone off for an hour and a half, and my site goes down, when am I going to hear or find out? I wish that it was set-up so it would just fix itself.

So, I hope that helps. As always it'd be great if you would subscribe. If you like this video give it a like, subscribe to the channel, ring that bell so you get notifications, and that helps other people find it.

Enjoy your Joomla sites, and God bless.


subscribe basic joomla

subscribe cybersalt

earn coins bn

Login Form