-
-
- Submit Updated Articles to Bing and Yandex with IndexNow in Joomla
- Add Published and Modified Date Meta Tags to Joomla
- Add Open Graph and Twitter Card Tags to Joomla
- Auto-Generate Meta Descriptions from Article Text in Joomla
- Add Noindex to Specific Pages in Joomla
- Verify Your Joomla Site with Google Search Console
-
- Add a View as Markdown Link to Joomla Articles
- Display the Last Modified Date in Joomla Articles
- Embed Iframes in Joomla
- Automatically Link Twitter (X) @mentions in Joomla Articles
- Open External Links in a New Tab in Joomla
- Display Estimated Reading Time in Joomla Articles
- Replace Old URLs in Joomla
- Search and Replace in Joomla
-
- Add a Footer Line to the Joomla Administrator
- Show a Staging Banner in the Joomla Administrator
- Remove the "All" Option from Admin List Limits in Joomla
- Add a Cookie Consent Banner to Joomla
- Make the Administrator Navigation Sticky in Joomla
- Add Google Fonts to Joomla
- Add a Facebook Messenger Chat Button to Joomla
- Add a Reading Progress Bar to Joomla
- Add a Custom Scrollbar to Joomla
- Show Confetti on a Thank You Page in Joomla
- Add Smooth Scrolling to Joomla
- Add a Back to Top Button in Joomla
- Add a WhatsApp Chat Button in Joomla
-
- Protect the Administrator with a Secret URL Key in Joomla
- Show a Welcome Message on First Login in Joomla
- Log Out Idle Administrators in Joomla
- Assign New Users to a Different User Group Automatically in Joomla
- Redirect Visitors by Country in Joomla
- Redirect Users After Login by User Group in Joomla
- Block User Registration with Certain Usernames in Joomla
- Block User Registration by Country in Joomla
- Block User Registration by Email Address in Joomla
- Block User Registration by IP Address in Joomla
- Remove the Forgot Password and Username Links in Joomla
- Remove the Generator Meta Tag in Joomla
- Let Users Log In with Their Email Address in Joomla
- Block Traffic by Country in Joomla
- Block Bot Traffic in Joomla
- Block Traffic by IP Address in Joomla
Clear the Cache with a Link in Joomla
Clear your Joomla cache with one click from a bookmark, without logging into the administrator, using one PHP snippet.
You fix a typo, save the article, and visitors still see the old version because Joomla serves it from the cache. Clearing it means logging into the administrator, opening System → Clear Cache and clicking Delete All. A private link can do the same in one click, straight from a bookmark. You can add it with one PHP snippet in Code Snippets.
The PHP snippet code
The snippet clears every cache group, the same way the Delete All button does, including the page cache. Then it reloads the page without the link's parameters and shows a short confirmation.
use Joomla\CMS\Cache\CacheControllerFactoryInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
// The secret your link must carry, as in ?cleancache=1&key=your-secret.
// Use a long random string and keep it private.
$secret = 'change-me';
// Do not edit below.
$app = Factory::getApplication();
$key = $app->getInput()->getString('key', '');
// Do nothing until you set your own secret, or when the key is wrong.
if ($secret === 'change-me' || !hash_equals($secret, $key))
{
return;
}
$cache = Factory::getContainer()
->get(CacheControllerFactoryInterface::class)
->createCacheController('', [
'defaultgroup' => '',
'storage' => $app->get('cache_handler', ''),
'caching' => true,
'cachebase' => $app->get('cache_path', JPATH_CACHE),
]);
$groups = $cache->getAll() ?: [];
foreach ($groups as $group)
{
$cache->clean($group->group);
}
// Reload the page without the link's parameters, and confirm it worked.
$uri = clone Uri::getInstance();
$uri->delVar('cleancache');
$uri->delVar('key');
$app->enqueueMessage(sprintf('Cache cleared (%d groups).', count($groups)));
$app->redirect($uri->toString());
Replace change-me with a long random string. Your link then looks like this, with your own address and secret:
https://yoursite.com/?cleancache=1&key=your-secret
The snippet does nothing while the secret is still change-me, or when the key in the link is wrong. That stops strangers from emptying your cache over and over.
How to add this snippet
- Install Code Snippets if it isn't installed already.
- Log into your Joomla backend.
- Go to Components → Tassos Code Snippets.
- Click New.
- Enter a title, for example Clear cache link.
- Set Code Type to PHP.
- Set Insertion Method to Auto-Insert Locations.
- Set Location to On Page Load.
- Paste the code above into the editor.
- Replace
change-mewith your own secret. -
Open the Conditional Logic tab:
- Set Display on to Selected Pages.
- Click New Condition Set.
- Click Select Condition and choose URL - Query String.
- In URL, enter
cleancache=1.
- Click Save & Close.
With the Conditional Logic rule in place, the snippet only runs when the address contains cleancache=1. The URL - Query String condition is free.
Check that it works
- Open your link, with your own address and secret.
- Look at the top of the page.
The page reloads without cleancache and key in the address and shows "Cache cleared" with the number of cache groups it emptied. The link works on any page of your site and brings you back to the same page. Open it with a wrong key, and the page loads as usual with nothing cleared.
The link clears Joomla's own cache. A CDN like Cloudflare, or a cache on your server, keeps its own copy, which you clear there.
For more ways to speed up your site, see Defer JavaScript in Joomla. To learn more about how PHP snippets work, read the PHP snippet docs.