Skip to content
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

Introduce taxonomy-specific cache invalidation methods #8634

Open
wants to merge 15 commits into
base: trunk
Choose a base branch
from

Conversation

spacedmonkey
Copy link
Member

Revised caching logic by introducing wp_cache_set_taxonomy_last_changed and wp_cache_get_taxonomy_last_changed functions to track individual taxonomy changes. Updated related areas to leverage these methods for more granular cache management, improving efficiency and accuracy.

Trac ticket:


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Revised caching logic by introducing `wp_cache_set_taxonomy_last_changed` and `wp_cache_get_taxonomy_last_changed` functions to track individual taxonomy changes. Updated related areas to leverage these methods for more granular cache management, improving efficiency and accuracy.
Copy link

github-actions bot commented Apr 1, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props spacedmonkey.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Added support for retrieving multiple taxonomy-related cache keys at once using `wp_cache_get_multiple`. This improves performance and ensures consistency when fetching last changed timestamps for taxonomies.
Corrected the placement of arguments in the array_map function to align with proper syntax. This resolves potential errors in generating cache keys for taxonomies.
Copy link

github-actions bot commented Apr 2, 2025

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Updated `wp_cache_get_taxonomies_last_changed` to return a string instead of a float and added handling for empty taxonomy arrays. This ensures better consistency and prevents possible errors when no taxonomies are provided.
Adjusted assertions to reflect correct query count changes in getAdjacentPost tests and updated cache key usage in getTerms tests to ensure accuracy. These changes improve test reliability and align with the expected data structure.
Added a check to ensure the 'taxonomy' key exists in tax queries before accessing it. This prevents potential PHP notices or errors when the key is missing.
Replaced multiple individual cache calls with batch operations for better performance and maintainability. This change minimizes overhead when clearing taxonomy-related cache entries.
Ensure `wp_cache_get_taxonomy_last_changed()` handles empty taxonomy inputs by returning the default last changed value. Refine `wp_cache_get_taxonomies_last_changed()` to perform filtering only where input is used, improving efficiency.
Introduce new PHPUnit tests to verify proper cache invalidation behavior for terms and queries involving different taxonomies. These tests ensure term and query caches are refreshed or retained as expected, improving cache consistency validation.
Document the version for newly added or modified functions using @SInCE tags. This helps maintain clarity about when changes were introduced in the codebase.
This commit introduces PHPUnit tests for `wp_cache_get_taxonomy_last_changed` and `wp_cache_get_taxonomies_last_changed` functions. The tests ensure correct behavior for empty, single, and multiple taxonomy inputs, including duplicate handling.
Added unit tests to ensure that adding, updating, or deleting term metadata invalidates the term query cache correctly. These tests cover scenarios for `add_term_meta`, `update_term_meta`, and `delete_term_meta` to verify expected cache invalidation behavior.
Updated the assertion to reflect the expected number of queries increasing from 4 to 5, due to the inclusion of term data. This ensures the test correctly validates the query behavior after the change.
Refactors caching logic to account for changes in term meta data by appending a "last changed" timestamp. Additionally, simplifies `wp_cache_clear_term_meta()` to only adjust relevant cache keys, ensuring more accurate and efficient cache behavior.
Removed unused priority and argument count parameters from wp_cache_clear_term_meta callbacks for added, updated, and deleted term meta actions. This reduces unnecessary complexity and aligns with standard usage patterns.
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.

1 participant