Skip to main content
2 of 5
deleted 127 characters in body
Ricardo
  • 265
  • 1
  • 20

Two Cache::remember in same method

I'm using Cache::remember to Cache 3 results in my action, 2 in same call to Cache::remember, it's work but I have 2 questions (below) about how I can join this Cache::remember call.

  1. I could use two Cache::remember in same method ?

  2. I coudl join this two Cache::remember (I need change the first param)?

    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'));
    

    }

Ricardo
  • 265
  • 1
  • 20