Page 1 of 1

How to execute clear cache from code?

Posted: Tue Jul 24, 2018 8:30 am
by andrzej_szpak
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

Re: How to execute clear cache from code?

Posted: Tue Jul 24, 2018 10:49 am
by gws
try https://extensions.joomla.org/extension/cache-cleaner/ you will need the pro version for scheduled cache cleaning.

Re: How to execute clear cache from code?

Posted: Wed Jul 25, 2018 7:39 am
by SharkyKZ
To clean cache for a specific component/extension:

Code: Select all

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

Code: Select all

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

Code: Select all

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