How to execute clear cache from code?

Need help with the Administration of your Joomla! 2.5 site? This is the spot for you.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Post Reply
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Sat Jun 02, 2012 10:50 pm

How to execute clear cache from code?

Post by andrzej_szpak » Tue Jul 24, 2018 8:30 am

I have a cron job to fetch data from a 3d party API to display Joomla pages using a component.
Sometimes something fails with this process and data are broken.
Until next cron job pages are rendered incorrectly.

Since website has a heavy load, i have cache enabled to speed the website.

So when pages are rendered incorrectly they are cached.

So after next cron job data are correct, but cache is still invalid.

I need to go to admin settings and clear cache manually to fix it.

So, does anyone have a code, or something i could use to clear cache? I could execute it in cron job or something.

Ps. i am using Shared Hosting with no shell access

Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3492
Joined: Tue Aug 23, 2005 1:56 pm
Location: South coast, UK

Re: How to execute clear cache from code?

Post by gws » Tue Jul 24, 2018 10:49 am

try you will need the pro version for scheduled cache cleaning.
Last edited by toivo on Wed Jul 25, 2018 11:27 am, edited 1 time in total.
Reason: mod note: changed the link to point to JED

Joomla! Ace
Joomla! Ace
Posts: 1332
Joined: Fri Jul 05, 2013 10:35 am
Location: Unknown

Re: How to execute clear cache from code?

Post by SharkyKZ » Wed Jul 25, 2018 7:39 am

To clean cache for a specific component/extension:

Code: Select all

$cache = JCache::getInstance('callback', array('defaultgroup' => 'com_example'));

Code: Select all

$cache = JCache::getInstance('callback');
To clean all cache:

Code: Select all

$cache = JCache::getInstance('callback');
$cache->clean(null, 'notgroup');

Post Reply

Return to “Administration Joomla! 2.5”