Scriptproperties caching question

I have a plugin that responds to two properties values.

If I change either of the properties, the next time the plugin is executed, it appears to use the old value of the property, even though the cache should be cleared when the plugin is saved.

If I manually clear the cache in the Manager before the plugin executes, it responds correctly to the new values.

So first, why doesn’t saving the plugin clear the cache for its properties.

Second, is there anything I can do in the plugin to get fresh properties and avoid the issue?

I never have used script properties in plugins. I would use system settings. That way you have one place for settings and not several ones.

Plugin script properties don’t survive a package update containing the plugin. That’s another reason.

I could be wrong but it seems that when you change a plugin property and click the “Save” button, it generates 2 XHR-requests.

First one with the action element/plugin/update (that saves the plugin and clears the cache) and then another with the action element/propertyset/updatefromelement (that actually sets the properties-field).

So it seems the cache is cleared before the properties value is set.

@jako Good points. I generally do the same. This is one of my older plugins, written before I knew any better.

@halftrainedharry That makes fits with what I’m seeing. I think saving the plugin twice works as well as clearing the cache.

Out of curiosity, where is the properties cache? It’s not in the scripts cache.

There is a section pluginCache in the file core/cache/context_settings/.../context.cache.php.

Thanks. I never would have thought to look for them there. It’s odd that plugins are not cached in the scripts cache.

It’s also odd that the context cache is not cleared when saving plugins. It explains a lot of odd behavior I’ve seen with plugins over the years. I suspect that that cache is also not cleared when a plugin extra is removed in Package Manager.

It looks like they are cached there as well. But only the code (without the properties).

I believe the context cache is cleared, but the files are then immediately regenerated.
In this specific case, the files are regenerated before the properties value is set.

I’d call that a bug. Could you report it, since you’ve found the relevant code.

It also raises the question of why plugin code is cached in two separate places.

I agree with Bob. This is a bug. The properties should be updated before the context cache is regenerated, which is always done whenever it is refreshed.

I created a github issue:

Thanks! ******************************