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
- change settings manually to make them different
- clear cache and open the page, plugin runs at the end it will replicate the value (now both settings fields are the same)
- (problem) the plugin keeps running every time I open the page because the settings still different
- 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!!!