4 Responses to “Reducing postmeta queries with update_meta_cache()”

  1. WordPress already does this by default for any query going through the posts_results filter, no? What am I missing?

    • It’s in general there when cache_results=true or cache_results is empty, but when using a persistant object such as memcache this is skipped as per this changeset. This makes sense in general as updating the remote caches is relatively expensive, but when you use postmeta a lot the database queries get more expensive than the cache updates.

      • Good point, I forgot about that tweak. I’ve already had a plugin author ping me about implementing this, though — the extra explanation for the “why” would really help.

        Most of the time for someone writing code that gets distributed, it probably makes sense to just let the setup control what’s going on, rather than forcing the queries. The default situation is typically best. Ultimately, unless a developer benchmarks performance of their code under both persistent and non-persistent caching, they can’t make an informed decision here.

        A cool improvement to something like W3 Total Cache might be the ability to kick on cache_results. Not necessarily a UI option, but perhaps as part of a larger expansion into automatic tuning driven by under-the-hood benchmarks. That’d be cool — activate a plugin like that and it just knows what settings you need. :-)

        Cheers.

  2. Thanks Thorsten. It really helped me. And I must say saved my day.

    Andrew Nacin you are right. But what about if I don’t wanna use W3TotalCache object cache or database queries cache. As it causes issues on my site, so this manual way saved me headaches. Though WordPress does it by default but I still prefer taking control myself somtimes.

    And also it helped me with Taxonomies. I use taxonomy images and wordpress doesn’t / couldn’t cache my taxonomies as I was not querying them by WP_QUERY or query_posts etc. So This saved me again.

    Thanks Again.
    Syed

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 183 other followers

%d bloggers like this: