-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Control whether theme (e.g. theme.json
) cache usage is enabled through a dedicated function
#45912
Comments
My main concern is what the developer experience is like. I'd recommend against using a filter for this reason, as it requires people to write a callback to the hook. In comparison, setting a constant is a widespread practice: it just works out of the box. The second question is whether we should use
I don't see an issue with using |
Massive +1 to this. Is really bad to use I vote for either a new const or use |
You can set a constant based on my proposal. My proposal is to use an approach that caters for both simplicity and flexibility: Feel free to use a constant if that's sufficient for your use-case, or use a filter if you need a more dynamic approach. The constant would define what is the default value for the filter. FWIW, writing a callback is not necessary if you want to use the filter for a simple way: You can simply use something like
+1, which is why I'm proposing a solution that allows reusing something existing.
I think either may be a reasonable approach, depending on what you're doing. I'm leaning towards To be clear, I'm still undecided myself which constant is more appropriate here, I'm slightly leaning towards Using an existing constant as a baseline for controlling theme cache is good, as it allows to reuse what's familiar. Having that existing constant be the only way though lacks flexibility, since the constant has a way broader purpose and furthermore is a constant so can't be dynamically altered at runtime. This is why I'm proposing a function which would be a combination of constant (whichever we decide on) plus filter. |
So, if I understand correctly, your current view is that we should do function wp_theme_json_cache_enabled() {
return apply_filter( 'wp_theme_json_cache_enabled', WP_DEBUG );
} Does that sound about right? I don't see anything that would qualify as a blocker, though my main question is: why? Why do we need this special setup for the caches related to |
Correct, something like that is what I am proposing.
Because the cache around
|
Interesting point, thanks for clarifying. I went to look at another place I know that caches data coming from files and not database: Note that I insist in the constant as the primary API because of its proven good developer experience: its value does not rely on being an one-liner (like some filter would), but on working on multiple situations. For example: one line in |
@oandregal That's interesting indeed - also that the persistent caching there is off by default. It looks like another use-case than what we're doing around For reference, this was introduced a very long time ago in https://core.trac.wordpress.org/changeset/20020, as part of https://core.trac.wordpress.org/ticket/20103. Unfortunately no information provided really on what use-case would justify enabling the filter. |
Leaving a note here to re-add the test that was removed in #45993, since this function will enable testing this again. |
Cross-posting from the PR for this (#46791 (comment)):
|
Now that |
Thanks @joemcgill for the reminder, this can indeed be closed now that we have |
What problem does this address?
Several places (e.g. #45372, #45679, #45882) now check for the
WP_DEBUG
constant to decide whether to useWP_Object_Cache
to cache expensive logic aroundtheme.json
parsing etc. It is still unclear whether that is the best approach, but most importantly, as this becomes more and more spread out, we should bring that into a single dedicated function. This function can then be used in all of these places, so that we can focus the conversation on the exact approach (even potential changes over the next few weeks) on just that function and not tons of other PRs.Being able to bypass cache is crucial in these situations for theme developers while they are developing a theme. It is probably almost never relevant in production; e.g. when a theme is updated, we can manually invalidate cache anyway as that is detectable within WordPress. The problem is that direct file modifications e.g. during theme development are not detectable so we cannot invalidate cache reliably for that. To provide a good theme developer experience, we should therefore allow bypassing these specific caches.
What is your proposed solution?
wp_theme_cache_enabled()
WP_DEBUG
orin_array( wp_get_environment_type(), array( 'local', 'development' ), true )
for the baseline value. I would now lean towards the latter, as this is less about debugging than it is about working in a development environment (as you are developing a theme, that's when this is most relevant).wp_theme_cache_enabled
to allow for this to be modified specifically or at runtime.WP_DEBUG
checks, similar for any future code may add more use ofWP_Object_Cache
around theme related logic.Let's discuss the exact logic within the function; but I think the overall function approach to have this centralized would definitely be a big plus already.
cc @mmtr @oandregal @spacedmonkey
The text was updated successfully, but these errors were encountered: