0
votes

The problem is with many records in products table and each client has own prices for product (product_prices).

Products are paging, ordering and display per page managed by clients.

I wrote own custom pagination based on http://www.jotlab.com/2010/pagination-caching-with-cakephp

But when client change ordering or display per page the cache it's created newly and this idea for cache it's not good.

I looking-for best solutions for caching many products with many prices.

1

1 Answers

0
votes

You can cache products per page, and than manualy assign settings for pagination:

$products_all_count = ???// you must count all products that match your conditions
$curr_page = (!empty($this->request->query('page')))? (int)$this->request->query('page') : 1;
$products_cache_key = 'product_' $products_all_count . '_page_' . $curr_page;
$products = Cache::read($products_cache_key);

$products_sett = array();
$products_sett['page'] = $curr_page;            
$products_sett['limit'] = 100; // defined limit per page


if (!$products) {

 // all conditions, settings etc.
 $products = $this->Paginator->paginate('Product');
 Cache::write($products_cache_key, $products);

} elseif (is_array($products)) {

 $this->request->params['paging'] = array(
    'Product' => array(
        'current' =>  $products_sett['limit'] * $products_sett['page'],
        'count' => $products_all_count,
        'prevPage' => (($products_sett['limit'] * $products_sett['page']) <= $products_sett['limit'])? false : true,
        'nextPage' => (($products_sett['limit'] * $products_sett['page']) >= $products_all_count)? false : true,
        'pageCount' => ceil($products_all_count / $products_sett['limit']),
        'limit' => $products_sett['limit'] ,
        'page' => $products_sett['page'],
        'options' => array()
    )
 );

}