Exemplo n.º 1
0
 /**
  * Internal method to get the latest photos
  * @param int $limit Limit
  * @return array
  * @uses MeInstagram\Utility\Instagram::recent()
  */
 protected function _latest($limit = 15)
 {
     //Tries to get data from the cache
     $photos = Cache::read($cache = sprintf('latest_%s', $limit), 'instagram');
     //If the data are not available from the cache
     if (empty($photos)) {
         list($photos) = Instagram::recent(null, $limit);
         Cache::write($cache, $photos, 'instagram');
     }
     return $photos;
 }
 /**
  * Views a photo
  * @param string $id Media ID
  * @return \Cake\Network\Response|null|void
  * @uses MeInstagram\Utility\Instagram::media()
  */
 public function view($id)
 {
     //Tries to get data from the cache
     $photo = Cache::read($cache = sprintf('media_%s', md5($id)), 'instagram');
     //If the data are not available from the cache
     if (empty($photo)) {
         //It tries to get the media (photo). If an exception is thrown, redirects to index
         try {
             $photo = Instagram::media($id);
         } catch (NotFoundException $e) {
             return $this->redirect(['action' => 'index'], 301);
         }
         Cache::write($cache, $photo, 'instagram');
     }
     $this->set(compact('photo'));
 }