public function getAll(){
if( !cache('PACKS')) {
$cached = ['packs' => $this->packs, 'v' => 1];
cache('PACKS',$cached,60);
}
return cache('PACKS');
}
It is a codeigniter function which uses memcahced. It has two calling of cache('PACKS'), how can I refactor this use just one times, and give back te correct result always?
Here's an upgrade:
public function getAll(){
$cached = cache('PACKS');
if(!$cached) {
$cached = ['packs' => $this->packs, 'v' => 1];
cache('PACKS',$cached,60);
}
return $cached;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.