What is the simplest way to clear a group's cache in Joomla via php, when caching disabled?

by Obscerno   Last Updated May 21, 2020 19:10 PM

So background: I'm making a caching plugin that clears our site and CDN caches when content is saved. In this instance, I want to clear the site cache for one group.

My original attempt looked something like this:

$cache = JFactory::getCache('cachegroup');

That didn't work. I did some research and saw SharkyKZ in the Joomla forums recommend this structure:

$cache = JCache::getInstance('callback');

That also didn't work for me. I suspected it had something to do with the fact that caching is disabled on our site, so I tried adding $cache->setCaching(1); to both sets of code and that didn't work either.

Finally I dug into the Joomla code and looked at how their cache component handles it; and ended up with this working code:

$conf = JFactory::getConfig();

$options = array(
    'defaultgroup' => '',
    'storage'      => $conf->get('cache_handler', ''),
    'caching'      => true,
    'cachebase'    => $conf->get('cache_path', JPATH_SITE . '/cache')

$cache = JCache::getInstance('', $options);

So I have working code, but I would...

  1. Like to understand why it works, and
  2. Like to know if there is a simpler or superior way to accomplish this.

Related Questions

Help no articles

Updated May 25, 2015 22:04 PM

custom component no-cache setting

Updated March 27, 2015 12:03 PM

CSS Change won't apply - Where could the cache be?

Updated February 25, 2017 07:10 AM

Joomla cache handler only shows memcached

Updated April 04, 2015 02:04 AM

Caching a page separately for users and guests?

Updated November 13, 2018 22:10 PM