Skip to content

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

Open

Description

@deJaya

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.

Activity

  1. travisbotello commented on Apr 16, 2024

    @travisbotello

    Confirmed. Bumping it :)

  2. Mark-H commented on Apr 16, 2024

    @Mark-H
    Member

    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?

  3. travisbotello commented on Apr 16, 2024

    @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?

    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.

  4. deJaya commented on Apr 16, 2024

    @deJaya
    Author

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

  5. deJaya commented on Apr 16, 2024

    @deJaya
    Author

    There was some discussion here

  6. travisbotello commented on Apr 16, 2024

    @travisbotello

    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.

  7. verstratenbram commented on Apr 22, 2024

    @verstratenbram

    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.

  8. Mark-H commented on Apr 22, 2024

    @Mark-H
    Member

    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' => [],
    ]);
    
  9. verstratenbram commented on Apr 22, 2024

    @verstratenbram

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

  10. verstratenbram commented on May 7, 2024

    @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.

  11. meeheee commented on May 13, 2025

    @meeheee

    +1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions