Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
deJaya opened this issue Jan 10, 2024 · 10 comments

Comments

@deJaya
Copy link

deJaya commented Jan 10, 2024

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.

@travisbotello
Copy link

Confirmed. Bumping it :)

@Mark-H
Copy link
Member

Mark-H commented Apr 16, 2024

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?

@travisbotello
Copy link

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.

@deJaya
Copy link
Author

deJaya commented Apr 16, 2024

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

@deJaya
Copy link
Author

deJaya commented Apr 16, 2024

There was some discussion here

@travisbotello
Copy link

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.

@verstratenbram
Copy link

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.

@Mark-H
Copy link
Member

Mark-H commented Apr 22, 2024

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' => [],
]);

@verstratenbram
Copy link

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

@verstratenbram
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants