Skip to main content
edited tags; edited title
Link
200_success
  • 144.1k
  • 22
  • 188
  • 473

Two Using Cache::remember in same methodfor banners and stores

added 8 characters in body; edited tags
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

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.:

  1. Could I could use two Cache::remembers in the same method  ?

  2. Could I could join thisthese two Cache::remembers (I need change the first param)?

  3. 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'));
}

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 could join this two Cache::remember (I need change the first param)?

  3. It's 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'));
    

    }

I'm using Cache::remember to cache 3 results in my action, 2 in the same call to Cache::remember. It works, but I have 2 questions about how I can join this Cache::remember call:

  1. Could I use two Cache::remembers in the same method?

  2. Could I join these two Cache::remembers (I need change the first param)?

  3. Is 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'));
}
added 65 characters in body
Source Link
Ricardo
  • 265
  • 1
  • 20

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 coudlcould join this two Cache::remember (I need change the first param)?

     
  3. public function favoriteStores() { $userId = $this->Auth->user('id'); $username = $this->Auth->user('username');It's 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'));
    

    }

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

    }

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 could join this two Cache::remember (I need change the first param)?

     
  3. It's 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'));
    

    }

deleted 127 characters in body
Source Link
Ricardo
  • 265
  • 1
  • 20
Loading
Source Link
Ricardo
  • 265
  • 1
  • 20
Loading