/** * 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')); }