Skip to content

Instantly share code, notes, and snippets.

@cakephp-tutorial
Created February 27, 2016 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cakephp-tutorial/4f7b011d95ce07fb1b63 to your computer and use it in GitHub Desktop.
Save cakephp-tutorial/4f7b011d95ce07fb1b63 to your computer and use it in GitHub Desktop.
<?php
public function find($type = 'first', $params = array(),$cacheParams = array()){
$doQuery =true;
if( isset($cacheParams['cache']) && !empty($cacheParams['cache'])){
$cacheConfig = null;
if(isset($cacheParams['cacheConfig']) && !empty($cacheParams['cacheConfig'])){
$cacheConfig = $cacheParams['cacheConfig'];
}
$cacheName = $this->name.'-'.$cacheParams['cache'];
$data = Cache::read($cacheName,$cacheConfig);
if($data == false){
$data = parent::find($type,$params);
Cache::write($cacheName,$data,$cacheConfig);
}
$doQuery = false;
}
if($doQuery){
$data = parent::find($type,$params);
}
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment