Skip to content

Conversation

@darylldoyle
Copy link
Collaborator

Description of the Change

This pull request improves the logic for enabling or disabling the class loader cache in the module initialization process, making it more flexible and testable. The main change is the introduction of a new method that centralizes the decision for using the cache, along with updated documentation and comprehensive tests.

Class loader cache logic improvements:

  • Added a new protected method should_use_cache() in ModuleInitialization.php to determine whether the class loader cache should be used, based on environment type and specific constants. This replaces the previous inline logic and allows for easier testing and extension.
  • Updated the cache usage condition in the get_classes() method to use the new should_use_cache() method, improving clarity and maintainability.

Configurability and documentation:

  • Updated the documentation in Modules-and-Initialization.md to describe how to disable class caching using the new TENUP_FRAMEWORK_DISABLE_CLASS_CACHE constant, especially for hosts that do not support file-based caching.

Testing enhancements:

  • Added a series of tests in ModuleInitializationTest.php to cover all branches of the new should_use_cache() logic, ensuring correct behavior under different environment conditions and constant definitions.
  • Imported the Brain\Monkey\Functions\stubs utility in the test file to facilitate function stubbing for environment simulation.

How to test the Change

Run the PHPUnit tests

Changelog Entry

  • Added - New option to disable file-based caching

Credits

Props @darylldoyle, @fabiankaegy, @dustinrue

Checklist:

@darylldoyle darylldoyle self-assigned this Nov 13, 2025
@fabiankaegy
Copy link
Member

Lol.... I literally just now created #27 😂 😂 😂 😂

@fabiankaegy
Copy link
Member

But your's is much nicer so I'll close mine 👍

fabiankaegy
fabiankaegy previously approved these changes Nov 13, 2025
Copy link
Member

@fabiankaegy fabiankaegy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! :)

@darylldoyle darylldoyle merged commit 95837f9 into develop Nov 13, 2025
3 checks passed
@darylldoyle darylldoyle deleted the feature/allow-skipping-caching branch November 13, 2025 17:30
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

Successfully merging this pull request may close these issues.

2 participants