• peter8nss

    (@peter8nss)


    In auction-description-secondlayout-tabs.php it looks as though the caching is the wrong side of the query. Normally I would expect to see logic like this:

    $value = get cache
    if (! exists) {
    $value = do database query
    save $value in cache
    }

    So the database query workload is avoided if the value can be read from the cache. Your code appears to do the opposite.

    // *** Always do the query ***
    $query = $GLOBALS['wpdb']->get_results($wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wdm_bidders WHERE auction_id = %d ORDER BY id DESC", $auctionid ));

    $cache_key = 'wdm_bidders_unique_cache_key';
    $results = wp_cache_get( $cache_key, 'your_cache_group' );
    if ( false === $results ) {
    $results = $query;
    // Store the results in the cache
    wp_cache_set( $cache_key, $results, 'your_cache_group', 3600 ); // Cache for 1 hour
    } else {
    // *** If actually was in the cache use that (older) result instead ***/
    $results = $query;
    }

    Do you even want to use caching here? If the auction was moving fast, wouldn’t this mean you failed to display bids received for up to an hour!

    Would you be better to put a (configurable) LIMIT in the SQL so that you only showed the last few bids. Thus controlling the cost of the database query and reducing the size of the HTML you needed to send.

    You could even have special case code for when the limit was configured to zero – i.e. where no past bids were to be displayed.

The topic ‘Bidders caching error’ is closed to new replies.