Skip to content

Read a build-time class cache on any host, VIP included (1.x, non-breaking) - #43

Merged
darylldoyle merged 1 commit into
developfrom
feature/read-prebuilt-class-cache
Nov 5, 2026
Merged

darylldoyle merged 1 commit into
developfrom
feature/read-prebuilt-class-cache

Conversation

@fabiankaegy

@fabiankaegy fabiankaegy commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Description of the Change

Module discovery tokenizes every PHP file in a directory on each request wherever the runtime cache can't be written. On WordPress VIP that's every request, because should_use_cache() returns false there.

This backports the read side of #35 to 1.x, without its breaking change:

The command name, cache directory, filename and cache ID match feature/2.0.0 (CACHE_DIR_NAME, CACHE_FILENAME, CACHE_ID). A project that adds the build step for 1.x keeps it unchanged through the 2.0.0 upgrade, and 2.0.0 then removes the runtime writes.

Not included from #35: the loader debug page, runtime-cache removal, the #30 fix and the upgrade docs. Those stay in 2.0.0.

Why now

The fueled.com 2026 build runs 19 framework-based plugin and theme directories on VIP. Measured locally against copies of those directories, with VIP_GO_APP_ENVIRONMENT defined:

Time per request
Discovery (today on VIP) 264.6 ms
Reading the prebuilt cache 0.65 ms

Every directory returned the same class list either way. On fdc, plugin loading plus init is ~0.65 s of a ~1 s uncached request.

How to test the Change

  1. composer test on PHP 8.4: 28 tests pass, including the new PrebuiltClassCacheTest. It covers:

    • a generate-then-read round trip;
    • reading with VIP_GO_APP_ENVIRONMENT defined;
    • no cache on VIP: discovery runs and nothing is written;
    • corrupt and non-array cache files falling back (and the action firing);
    • the disable constant;
    • the command end to end, including exit code 1 without arguments;
    • the read-only driver never creating its directory.

    The suite errors on PHP 8.5 before any test runs, inside antecedent/patchwork, unrelated to this change.

  2. composer lint and composer static are clean. phpcs.xml gets Make the class-loader cache build-time and add a loader debug page #35's exclusion for direct filesystem calls in tests/.

  3. In a project: run vendor/bin/tenup-framework-generate-class-cache path/to/src, define VIP_GO_APP_ENVIRONMENT, and check that get_classes() returns the cached list without discovering.

Changelog Entry

Added - vendor/bin/tenup-framework-generate-class-cache builds a class-loader cache at build time, and get_classes() reads it on any host, WordPress VIP included.

Credits

Props Daryll Doyle and Ryan Leeson: the driver, command and cache format are from #35/#36.

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

Module discovery tokenizes every PHP file in a directory on each request
wherever the runtime cache can't be written, which on WordPress VIP is
always. This backports the read side of #35 without its breaking change:

- `vendor/bin/tenup-framework-generate-class-cache <dir> [<dir> ...]`
  writes class-loader-cache/class-loader-cache-v2.php (from #35).
- get_classes() reads that file when it exists, through #35's
  ReadOnlyFileDiscoverCacheDriver, on any host. A corrupt file fires
  `tenup_framework_cache_load_failed` and falls back to discovery.
- Without the file, behaviour is exactly 1.3.1's: the runtime cache in
  production and staging, none on VIP.

The command, path, filename and cache ID match feature/2.0.0, so a
build step added now keeps working after the upgrade.

Co-authored-by: Daryll Doyle <daryll.doyle@10up.com>
Co-authored-by: Ryan Leeson <ryan.leeson@get10up.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fabiankaegy
fabiankaegy force-pushed the feature/read-prebuilt-class-cache branch from 141cb71 to 147414e Compare November 5, 2026 12:10
@darylldoyle
darylldoyle marked this pull request as ready for review November 5, 2026 12:22
@darylldoyle
darylldoyle merged commit bba9377 into develop Nov 5, 2026
3 checks passed
@darylldoyle
darylldoyle deleted the feature/read-prebuilt-class-cache branch November 5, 2026 12:22
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