Opened 15 years ago
Closed 9 years ago
#14983 closed enhancement (wontfix)
Get cache object by field
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Cache API | Keywords: | has-patch needs-refresh needs-testing |
Focuses: | Cc: |
Description
Functions such as get_term_by()
don't check the object cache before performing their query. We should introduce a function for getting a cache object by its field/value pair to make these more efficient.
I've written a simple function, get_cache_object_by()
, which accepts $field
and $value
parameters in the same way get_term_by()
does, and an optional $group
parameter for the cache group.
get_term_by()
and other get_*_by()
functions could check the cache with this function before performing their query.
The function is compatible with external object cache plugins that use the cache
member variable of the $wp_object_cache
object, as they should.
Attachments (1)
Change History (12)
#2
follow-up:
↓ 3
@
15 years ago
I was also trying to make get_term_by() check the cache in #13170 but I like your approach better.
Some testing would be required, to see if this actually boosts performance in most cases or not.
#3
in reply to:
↑ 2
@
15 years ago
Replying to scribu:
I was also trying to make get_term_by() check the cache in #13170 but I like your approach better.
Some testing would be required, to see if this actually boosts performance in most cases or not.
It only loops over the cache objects for the corresponding group so it should be fairly quick.
My use case was where some tags were manually listed in the footer of a site. The code uses get_term_by()
but performs a query even though the terms are already displayed on the site and are in cache. Not sure where and how often get_term_by()
is used by default.
#4
@
15 years ago
It looks like the only other function that would benefit from get_cache_object_by()
would be get_page_by_title()
. get_user_by()
checks user objects that are cached by field (odd that this behaviour is different to term caching).
get_page_by_path()
would benefit but only when $page_path
is just a top level slug and not a path separated by slashes.
#8
@
14 years ago
From http://core.trac.wordpress.org/ticket/13170#comment:6:
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.
So, yes, this still warrants some thorough testing.
#11
@
9 years ago
- Milestone Future Release deleted
- Resolution set to wontfix
- Status changed from new to closed
The cache backends I am familiar with do not have any support for groups. I'm afraid that the current proposal - though great conceptually - is not going to work given this limitation. Field-specific lookups, like in get_term_by()
, will always need either (a) their own cache, or (b) to become wrappers for the more generic query, whose cache key is salted with an incrementor.
get_cache_object_by()
function. If this looks ok I'll patch it up.