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.

Clear the Cache with a Link in Joomla
Heads up! This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

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.

Keep the link private, because anyone who has it can clear your cache.

How to add this snippet

  1. Install Code Snippets if it isn't installed already.
  2. Log into your Joomla backend.
  3. Go to Components → Tassos Code Snippets.
  4. Click New.
  5. Enter a title, for example Clear cache link.
  6. Set Code Type to PHP.
  7. Set Insertion Method to Auto-Insert Locations.
  8. Set Location to On Page Load.
  9. Paste the code above into the editor.
  10. Replace change-me with your own secret.
  11. 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.
  12. 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

  1. Open your link, with your own address and secret.
  2. 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.

Last updated on Oct 15th 2026 18:10