Opened 12 years ago
Closed 11 years ago
#22526 closed defect (bug) (fixed)
Changing category doesn't invalidate cache
Reported by: | Whissi | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 3.9 | Priority: | normal |
Severity: | normal | Version: | 3.4.2 |
Component: | Cache API | Keywords: | has-patch needs-docs dev-feedback |
Focuses: | Cc: |
Description
Hi,
I am using object-cache.php Memcached v2.0.2 (Dropins) with the current WordPress version, but I don't think this has anything to do with the dropin.
I noticed that category changes don't invalidate/update the cache.
For example:
- Create a category "Foo".
- Assign some postings to "Foo".
- View your postings in backend and frontend, so that results get cached.
- Rename "Foo" category to "Bar".
- Reload some postings, which are in that category. But they still display the old "Foo" category instead the new "Bar" category name.
Flushing memcached would "solve" this problem, that's why I think renaming categories don't invalidate/update the cache.
Attachments (4)
Change History (21)
#3
@
11 years ago
- Keywords needs-patch needs-unit-tests added
- Milestone changed from Awaiting Review to 3.9
#5
@
11 years ago
- Keywords has-patch commit added; needs-patch removed
Bugs like this give me nightmares. 22526.diff keeps the post terms cache in sync with changes to a given taxonomy.
Introduces 3 new functions:
get_taxonomy_last_changed( $taxonomy )
set_taxonomy_last_changed( $taxonomy )
post_taxonomy_is_fresh( $id, $taxonomy )
post_taxonomy_is_fresh()
only needs to be called in get_object_term_cache()
. Added some unit tests for the functions and for the condition described in the ticket which, surprise surprise, was reproducible with a basic unit test.
#6
@
11 years ago
- Owner set to wonderboymusic
- Resolution set to fixed
- Status changed from new to closed
In 27101:
#7
@
11 years ago
- Keywords needs-docs added; needs-unit-tests commit removed
- Resolution fixed deleted
- Status changed from closed to reopened
Sorry to reopen, but the docs on get_taxonomy_last_changed()
, set_taxonomy_last_changed()
, and post_taxonomy_is_fresh()
are incomplete.
- All of the function parameters and returns need descriptions.
- All function descriptions should end in periods.
#9
@
11 years ago
- Keywords dev-feedback added
- Resolution fixed deleted
- Status changed from closed to reopened
r27101 introduces a bunch of new tax_last_changed cache groups, and each one will most likely have a single key. Perhaps we can use the existing terms
group to hold that? In get_taxonomy_last_changed
you can use wp_cache_add()
instead of _set()
which I believe can be faster on some cache backends.
Also, this seems to introduce quite a lot of new stuff, all of it for the little bug we're trying to fix. Why can't we just use clean_object_term_cache
like we do in wp_delete_term
? See 22526.2.diff, it passes the unit test added in r27099.
#10
@
11 years ago
You are correct about the terms
bucket, did that here: 22526.3.diff. Not using _set
requires _delete
and _add
, because every falsely value needs to be overwritten. Will look at your other fix now.
#11
@
11 years ago
I applied your patch and turned off my checks in get_object_term_cache()
and _get_term_hierarchy()
. Unit tests fail for both. Is .2.diff additional or a replacement?
#12
@
11 years ago
After thinking about it, I don't think delete/add
is an upgrade from set
. I can see the benefit of add
when your goal is "I want something in the cache, no matter what, so as long as its there, we're good" but set
is more appropriate for "the value needs to be overwritten, no matter what."
Also, for cleanliness' sake, I can see the reason to use the terms
bucket, so I will probably make that change, but WP doesn't give you any way to invalidate by group, so the change is really arbitrary.
#14
@
11 years ago
Sorry, re add vs set, I was only referring to the get_taxonomy_last_changed()
function. You already check $last_changed
. If that's false, then the value is not in cache, because microtime()
can not return false, so you don't really need to delete.
#15
@
11 years ago
Re .2.diff, it's only a fix for this ticket and you'll need to revert your changesets before applying it. I added 22526.4.diff which reverts (or partially reverts) r27142, r27141, r27102 and r27101, adds the fix in .2.diff:
$ phpunit --group 22526 OK (1 test, 2 assertions)
This also reverts the fix in #14485, I'll reopen it and add a new patch with a simpler fix.
Still an issue?