#13170 closed enhancement (worksforme)
get_term_by() should check object cache
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Cache | Version: | |
| Severity: | normal | Keywords: | has-patch |
| Cc: |
Description
A lot of queries could be saved if get_term_by() would first look in the term cache before calling $wpdb.
Attachments (3)
Change History (12)
Maybe add a slug cache.
wp_cache_add($term->slug, $term->term_id, "{$taxonomy}_slugs");
- Keywords dev-feedback removed
- Milestone changed from Unassigned to 3.1
In get_terms_by.2.diff: introduce and use wp_cache_get_group()
On multisite installs getting a group will return a colossal amount of data. You also can't assume the backend cache will support it. I think the only way we can do this is as we do users, adding a slug to id cache.
- Milestone 3.1 deleted
- Resolution set to worksforme
- Status changed from new to closed
Yeah, but that wouldn't cover names.
I think I'll just use a wrapper function for get_term_by()
Sorry, I keep seeing your comments after I post...
IMO, what would really be needed here is a way to retrieve an object by more than one key.
In the case of the object cache, this would mean storing a reference to the same taxonomy object in multiple groups.

I was thinking of adding a get_group() method to WP_Object_Cache, but I don't want to needlessly clone all the objects in the cache.
Anyway, current patch saved around 25% of queries on a complex front page.