Plugin reading settings from cache

Summary

Hello everyone.
I created a plugin that is running OnSiteRefresh and OnWebPagePrerender.
To avoid the plugin running all the time that it’s not necessary I’m comparing 2 fields in settings if they are different then go for it and replicate the values so next time they are going to be equal and will trigger a return; to avoid the code to run again.

The problem is that the settings fields are being called from cache so need to clear cache twice to get the result I need:

Step to reproduce

  1. change settings manually to make them different
  2. clear cache and open the page, plugin runs at the end it will replicate the value (now both settings fields are the same)
  3. (problem) the plugin keeps running every time I open the page because the settings still different
  4. clear the cache again to load values on step 2 then the plugin stop running

The code:

$setting1 = $modx->getOption('setting1');
$setting2 = $modx->getOption('setting2');

//if they are equal stop
if ($setting1=== $setting2) return;

//if not make them equal for the next time ;)
$setting = $modx->getObject('modSystemSetting', 'setting1');
$setting->set('value', $setting2);
$setting->save();

return;

Am I doing something wrong calling the plugin on OnSiteRefresh and OnWebPagePrerender?
if yes what system event should I use?. Tried many options no luck.

All I need is called the plugin “uncached” though that was plugins default.

Thanks for any help.

Cheers!!!

Give this a try for getting the values:

$obj1 = $modx->getObject( 'modSystemSetting, array('key =>'setting1'), false);

$setting1 = $obj1->get('value');

$obj2 = $modx->getObject( 'modSystemSetting, array('key =>'setting2'), false);

$setting2 = $obj2->get('value');

I think that will get you the values directly from the DB.

If that doesn’t work, you could always just write the values to a file or files.

1 Like

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.