4

I am working on a custom component and it works as intended as long as I do not have cache enabled.

In the admin section of the component, I have a view that can change the "component params":

$params = JComponentHelper::getParams( 'com_example' );
$params->set( 'customsetting', 'test' );

$componentid = JComponentHelper::getComponent('com_example')->id;
$table = JTable::getInstance('extension');
$table->load($componentid);
$table->bind(array('params' => $params->toString()));

if (!$table->check()) {
    echo $table->getError();
}
if (!$table->store()) {
    echo $table->getError();
}

and load that setting with

$params = JComponentHelper::getParams( 'com_example' );
$setting = $params->get( 'customsetting' );

As I mentioned, this works without cache. But with cache, I cannot update the setting.

I guess I need to clear the cache after I change the component parameters, but I could not figure out how.

I tried parent::cleanCache('com_hbmanager');, but it had no effect. https://docs.joomla.org/Cache also didn't help me finding a solution.

Is there a way to clear the cache for the parameters of a component?

2
  • I've just come across this question - did you get it sorted? I tried it out and it did cache it when the system Page Cache plugin was enabled, as you describe. However to get round it I cleaned the cache for "_system" before I read the parameters with getParams(). Looking at the code in ComponentHelper.php, that's what is passed to getCache() to load the parameters in the load() function. Commented Jan 2, 2020 at 14:44
  • I didn't find a way to do it yet. I will try your suggestion when I get a chance
    – jost21
    Commented Jan 4, 2020 at 14:53

1 Answer 1

1

Are you using custom caching or built-in ? I've never had problems with component cache.

I've put your snippet inside com_content and it worked despite cache was on.

You can delete all site cache via model:

JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_cache/models', 'Cache');
$model = JModelLegacy::getInstance('Cache', 'CacheModel');
$model->clean();
//$model->clean('_system'); SYSTEM_CACHE_ONLY

This is equivalent to:

$cache = JCache::getInstance('output', 
            [
                'defaultgroup'=>'',             
                'cachebase' => JPATH_SITE.'/cache' or JPATH_ADMINISTRATOR for admin cache
            ]);
$cache->clean();

System cache will rebuild _system as quick as you hit administrator area again :)

1
  • Thanks :) I don't recall all the details since the question is over 3 years old. I definitely did not use any custom caching. If you tried it just now, we also probably used different versions of Joomla.
    – jost21
    Commented Oct 17, 2022 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.