[Solved] Plugin Event Triggers on Wrong Time

Hello Everyone.

I got this Plugin that is writing in a setting a random number for the Etag in the website headers.
The idea is to modify the number every time the user save a chunk, snippet, template, TV.

With this what I’m trying to do is to tell the browsers reload a fresh version of every resource is opened (avoid cache) without needed to clear cache every single time changes are set.

Setting: etag

eTagHash Plugin: OnCacheUpdate, OnChunkSave, OnPluginSave, OnSnippetSave, OnTemplateSave, OnTemplateVarSave

The Code:

$value = mt_rand(10000000,99999999);
$setting = $modx->getObject('modSystemSetting', 'etag');
$setting->set('value', $value);

The problem: This is working so far so good, the problem is that it’s triggered when a resource is saved too, I don’t understand the reason so any help to avoid this will be welcome.

Thanks you very much!

The event OnCacheUpdate fires after the cache is cleared.
And when you save a resource, the cache gets cleared. So OnCacheUpdate probably gets invoked.

1 Like

@halftrainedharry You are THE MASTER OF THE UNIVERSE!!! :sunglasses: :sunglasses: :sunglasses:
Excellent, thank you very much mate!

One last question. is there a way to trigger the plugin when the cache is manually cleared?

Thanks :+1:


1 Like

Master @jako , thank you mate! :+1: