I have totalProduct count activated because I need it for other mod. So to speed up loading I have cached the totalProducts results like this:
Code: Select all
$cacheid='product.gettotalproducts.'.md5($sql);
$total=$this->cache->get($cacheid);
if ($total === false ) {
$query = $this->db->query($sql);
$total = $query->row['total'];
$this->cache->set($cacheid,$total);
}
Can Someone help how to cache also this results?
Code: Select all
protected $ymm_cache;
protected $ymm_where;
public function __construct($registry)
{
parent::__construct($registry);
$this->ymm_cache = $this->setYmmCache();
$this->ymm_where = $this->setYmmWhere();
}
private function setYmmCache()
{
$ymm_cache = '';
if(isset($this->session->data['ymm'])){
$ymm_cache .= '.' . (int)$this->session->data['ymm']['make'];
if(!empty($this->session->data['ymm']['model'])){
$ymm_cache .= '.' . (int)$this->session->data['ymm']['model'];
}
if(!empty($this->session->data['ymm']['engine'])){
$ymm_cache .= '.' . (int)$this->session->data['ymm']['engine'];
}
if(!empty($this->session->data['ymm']['year'])){
$ymm_cache .= '.' . (int)$this->session->data['ymm']['year'];
}
}
return $ymm_cache;
}
private function setYmmWhere()
{
$ymm_where = '';
if(isset($this->session->data['ymm'])){
$ymm_where .= "(p.product_id IN (SELECT p2y.product_id FROM " . DB_PREFIX . "product_to_ymm p2y WHERE p2y.make_id = '" . $this->session->data['ymm']['make'] . "'";
if(!empty($this->session->data['ymm']['model'])){
$ymm_where .= " AND p2y.model_id = '" . $this->session->data['ymm']['model'] . "'";
}
if(!empty($this->session->data['ymm']['engine'])){
$ymm_where .= " AND p2y.engine_id = '" . $this->session->data['ymm']['engine'] . "'";
}
if(!empty($this->session->data['ymm']['year'])){
$ymm_where .= " AND p2y.begin_year <= '" . $this->session->data['ymm']['year'] . "' AND p2y.end_year >= '" . $this->session->data['ymm']['year'] . "'";
}
$ymm_where .= ")";
if(($this->config->get('ymmfilter_search_universal') == '1') || (isset($this->request->get['route']) && $this->request->get['route'] != 'product/search')) {
$ymm_where .= " OR p.product_id IN (SELECT p2.product_id FROM " . DB_PREFIX . "product p2 WHERE p2.universal = '1')";
}
$ymm_where .= ") AND ";
}
return $ymm_where;
}
public function updateViewed($product_id) {
$this->db->query("UPDATE " . DB_PREFIX . "product SET viewed = (viewed + 1) WHERE product_id = '" . (int)$product_id . "'");
}