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.
Locked
andrzej_szpak
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Sat Jun 02, 2012 10:50 pm
Contact:

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

gws
Joomla! Champion
Joomla! Champion
Posts: 5883
Joined: Tue Aug 23, 2005 1:56 pm
Location: South coast, UK
Contact:

Re: How to execute clear cache from code?

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

try https://extensions.joomla.org/extension/cache-cleaner/ 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

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2863
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts 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'));
$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');


Locked

Return to “Administration Joomla! 2.5”