Cache the result of an expensive function in APC

$counts = apc_fetch('shop:brand_counts', $found);

// $found, not a truthiness test on $counts: a legitimately cached 0 or empty
// array would otherwise re-run the query on every request.
if ($found !== true) {
    $counts = shop_count_products_by_brand();
    apc_store('shop:brand_counts', $counts, 300);
}