ClientConfig icon indicating copy to clipboard operation
ClientConfig copied to clipboard

clientconfig.clear_cache does not clear the cache when ClientConfig settings are saved

Open deJaya opened this issue 2 years ago • 11 comments

Summary

ClientConfig's system setting clientconfig.clear_cache does not clear the cache when ClientConfig settings are saved

Step to reproduce

Set clientconfig.clear_cache to Yes [default]

Observed behavior

When saving a ClientConfig setting, the cache should be cleared [as I understand it] - but in all my tests, it's still necessary to manually clear the cache or call the setting uncached.

Expected behavior

MODX cache should be cleared

Environment

ClientConfig version 2.4.0-pl, MODX version 3.0.4-pl,
PHP version 8.2.

deJaya avatar Jan 10 '24 16:01 deJaya

Confirmed. Bumping it :)

travisbotello avatar Apr 16 '24 14:04 travisbotello

Just to confirm, you're saying it does not clear the resource cache (or a different one), and this is all with the standard cache setups?

Mark-H avatar Apr 16 '24 14:04 Mark-H

Just to confirm, you're saying it does not clear the resource cache (or a different one), and this is all with the standard cache setups?

I can just tell for myself, but I am running a default MODX 3.0.4. clientconfig.clear_cache is set to Yes. I render an example client config setting in the default template. When I change the value in client config and save it I would expect the cache to be cleared instantly. Instead the old values are still visible until I clear the cache either manually, or save a resource/chunk/snippet.

travisbotello avatar Apr 16 '24 14:04 travisbotello

That's the experience I have as well. Standard cache setup.

deJaya avatar Apr 16 '24 15:04 deJaya

There was some discussion here

deJaya avatar Apr 16 '24 15:04 deJaya

There was some discussion here

Yes, this is clearly a bug...I would expect client config to clear the whole cache after save when this setting is enabled.

travisbotello avatar Apr 16 '24 17:04 travisbotello

Running into this issue too. Possibly having something to do with https://github.com/modmore/ClientConfig/blob/master/core/components/clientconfig/processors/mgr/settings/save.class.php#L73

From the modx error log:

PHP warning: rmdir(/.../core/cache/resource/web/resources/): Directory not empty
PHP warning: rmdir(/.../core/cache/resource/web/): Directory not empty

Current workaround is to create a plugin on the ClientConfig_ConfigChange event and manually clearing the resource folder.

verstratenbram avatar Apr 22 '24 09:04 verstratenbram

Correct @verstratenbram - that's exactly the line that is supposed to wipe the resource cache clean and I'm not sure why it wouldn't. 😂

I've wondered if we need to change that to use the refresh() instead:

$this->modx->getCacheManager()->refresh([
    'resource' => [],
]);

Mark-H avatar Apr 22 '24 13:04 Mark-H

Hi @Mark-H, that seems to resolve the issue. Don't understand why the original code doesn't work though.

verstratenbram avatar Apr 22 '24 14:04 verstratenbram

I've looked a bit further into this issue.

The previous error messages Directory not empty can be ignored. This was because we are using a custom resource cache handler which uses the .cache.gz extension for cache files instead of the default .cache.php. Because of that the files were not getting deleted for some modCacheManager functions. We have resolved this issue by using the default extension instead.

There is still something odd happening though. Upon saving the client configuration and immediately reloading the front-end, the old values persist. Yet, when waiting for 2-3 seconds after saving and then reloading the front-end, the correct values appear.

Just to be clear, the resource cache does get cleared, but it gets filled with the old client config values if you refresh the front-end page fast enough.

verstratenbram avatar May 07 '24 14:05 verstratenbram