I'm using Cache::remember
to Cachecache 3 results in my action, 2 in the same call to Cache::remember
. It works, it's work but I have 2 questions (below) about how I can join this Cache::remember
call.:
Could I could use two
Cache::remember
s in the same method ?Could I could join thisthese two
Cache::remember
s (I need change the first param)?It'sIs it possible load model outer
Cache::remember
?public function favoriteStores() { $userId = $this->Auth->user('id'); $username = $this->Auth->user('username'); list($fullBanners, $smallBanners,) = Cache::remember( 'banners', function(){ $this->loadModel('Banners'); $fullBanners = $this->Banners->full(); $smallBanners = $this->Banners->small(); return [$fullBanners, $smallBanners]; }); list($stores, $favoriteStores) = Cache::remember( 'stores', function(){ $stores = $this->Stores->myStores($this->Auth->user('id')); $favoriteStores = $this->Stores->favoriteStores(); return [$stores, $favoriteStores]; }); $this->set(compact('fullBanners', 'smallBanners', 'userId', 'username', 'stores', 'favoriteStores'));
}
public function favoriteStores()
{
$userId = $this->Auth->user('id');
$username = $this->Auth->user('username');
list($fullBanners, $smallBanners,) = Cache::remember(
'banners', function(){
$this->loadModel('Banners');
$fullBanners = $this->Banners->full();
$smallBanners = $this->Banners->small();
return [$fullBanners, $smallBanners];
});
list($stores, $favoriteStores) = Cache::remember(
'stores', function(){
$stores = $this->Stores->myStores($this->Auth->user('id'));
$favoriteStores = $this->Stores->favoriteStores();
return [$stores, $favoriteStores];
});
$this->set(compact('fullBanners', 'smallBanners', 'userId', 'username',
'stores', 'favoriteStores'));
}