Delete only theme-related caches when saving changes #685
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related to #655, #654
This PR changes how the cache is deleted when you save changes to a theme:
Delete the database cache as well as the object cache
As I understand it, the wp_cache_flush() function deletes only the object cache. On the other hand, the pattern uses the database cache via the Transient API (Source).
Therefore, I think that
wp_cache_flush()
cannot completely solve the problem reported in #655.In my testing in the local wp-env environment, the content did not appear in the editor canvas after saving a modified template unless I deleted the database cache or changed the value of the
DEVELOPMENT_MODE
constant totheme
.Delete only the theme cache, not all caches
wp_cache_flush()
function deletes all object caches. Therefore, it may have unintended negative effects on sites that are trying to improve performance by using object caches.WP_Theme (wp_get_theme())->cache_delete() method properly deletes the object cache for the theme and the database cache for the pattern (Source).
Testing Instructions
First of all, I would be grateful if you could confirm whether the problem reported in #655 still occurs in the wp-env environment and test whether this PR solves the problem.
If this PR is useful, we may evaluate the effectiveness of the
wp_cache_flush()
function used in other places individually and replace it with a different cache deletion method similar to this PR.The video below shows that the issue reported in #655 still occurs in the wp-env environment.
a164276e19a6881b67d82c56cfc5bb8b.mp4