URL-to-post lookups cache resolutions for a week without invalidation
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 58/100
Research direction
Start in src/Utils/class-utils.php at the two cache writes around lines 446 and 481, then trace how get_post_id_by_url() is used and how post-change hooks are registered. Reproduce with a persistent object cache using the steps in the issue, and check existing tests for URL-to-post lookups. Done means changes to a post’s status, slug, or existence cannot leave a stale lookup result across the described paths.
Written by the indexing model from the issue text.
Description
Describe the bug
Utils::get_post_id_by_url() caches its result under url-to-postid-<hash> for WEEK_IN_SECONDS, in two places: src/Utils/class-utils.php:446 for the url_to_postid() match, and :481 for the slug match. Nothing invalidates that key — there is no wp_cache_delete() for it, and no hook on post changes.
A cached resolution can therefore disagree with the site for up to a week after the post behind a URL changes. Visibility is checked on return, so this is a freshness and correctness issue rather than an access one.
To Reproduce
On a site with a persistent object cache:
- Create a private page with the slug
example-slug. - Resolve a URL ending in
/example-slug/through any feature that maps URLs to posts, so the result is cached. - Publish a post with the same slug. WordPress keeps slugs unique only within a post type, so a page and a post can share one.
- Resolve the same URL again.
The lookup keeps returning the earlier resolution until the entry expires. Clearing the object cache returns the expected post.
The same cause affects neighbouring cases: a cached post that is later unpublished, deleted, or given a different slug.
Expected behavior
The lookup reflects the current state of the site, or the cached entry is invalidated when the posts behind it change.
Environment
wp-parsely 3.24.x, any WordPress version. Only observable on sites with a persistent object cache; without one the entry lasts a single request.
Additional context
Raised by CodeRabbit on #4662.
Possible directions: invalidate the key on save_post/deleted_post, shorten the TTL, or key the entry so that a stale hit cannot occur. Addressing it at a single call site would leave the other paths above untouched.
- Dominant language
- PHP
- Stars
- 67
- Forks
- 38
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 79
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Parsely/wp-parsely
-
Bug Feature: Engagement Boost wp-parsely
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Parsely/wp-parsely#4856 ·
Maintainers usually reply within 1 day
-
Bug Feature: Engagement Boost wp-parsely
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Parsely/wp-parsely#4855 ·
Maintainers usually reply within 1 day
-
Bug Feature: Engagement Boost wp-parsely
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Parsely/wp-parsely#4854 ·
Maintainers usually reply within 1 day
-
wp-parsely
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Parsely/wp-parsely#4753 ·
Maintainers usually reply within 1 day
-
Documentation wp-parsely
Difficulty 3/5 1-2 days Newbie friendliness 74/100
Parsely/wp-parsely#4559 ·
Maintainers usually reply within 1 day
All issues in Parsely/wp-parsely
Similar issues
-
15.0
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
opnsense/plugins#5976 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
open-telemetry/opentelemetry-php-distro#176 ·
Maintainers usually reply within 2 days
-
No Code Attached Yet
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
joomla/joomla-cms#48941 ·
Maintainers usually reply within 1 day
-
needs-triage Platform(Default)
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day