Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #37762, comment 8


Ignore:
Timestamp:
09/12/2016 01:23:35 AM (9 years ago)
Author:
Dang Vu
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #37762, comment 8

    initial v1  
    1 Replying to [comment:5 boonebgorges]:
    2 
    3 > If you are running a persistent object cache like Memcached, then the cached post objects are available across page loads. Even within a single pageload and without a persistent cache, other functions in WP fetch data from the `'posts'` cache group. `WP_Query::posts` is not intended to be a cache, but is a list of query results.
    4 
    5 
    6 If we use`$wp_query` as the main DTO and render everything via it, post objects in cache is useless.
    7 Anyway, I'm currently not familiar with WordPress architecture, if ''other functions in WP fetch data from the `'posts'` cache group'', then it makes sense.
    8 
    9 
    10 > `cache_results` is fairly poorly named. Introduced in [14310], it really means "populate all caches related to query results". This includes the 'posts' cache as well as the taxonomy and metadata caches. See `update_post_caches()`. In [14665], `cache_results` was set to `false` when a persistent object cache is in use, because the repeated (unnecessary) round trips to Memcached were causing performance issues; see #12611. The `posts` array in `WP_Query` began to touch the 'posts' cache in [21559], which made `cache_results` more ambiguous: it now determines whether metadata and taxonomy should automatically be loaded into the cache, rather than the post objects. And this latter fact is confused by the fact that we have separate `update_post_meta_cache` and `update_post_term_cache` params.
    11 
    12 
    13 We should separate `update_post_meta_cache` and `update_post_term_cache` params and make it independent from `cache_results` param. These lines of code is ambiguous:
    14 
    15 {{{
    16 $this->posts = array_map( 'get_post', $this->posts );
    17 
    18 if ( $q['cache_results'] )
    19     update_post_caches($this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache']);
    20 }}}
    21 
    22 
    23 Since `get_post` has already added post objects to cache, `update_post_caches()` is unnecessary.
    24 Other problem is if `cache_results` is set to `false`, post metadata and term metadata will not be cached.
    25 
    26 
    27 > What is the reason for wanting to prevent post objects from being loaded into the cache? Is it a performance issue like described in #12611?
    28 
    29 
    30 No, performance is almost unnoticeable unless we're querying thousands of posts in a single query.
    31 
    32 
    33 I'm learning WordPress and find out the `cache_results` param doesn't work as expected so I have created this ticket. Now, I have understood why it didn't work. Thank for your time and hope I can see the enhancement in the next release!