Created
January 29, 2019 23:16
-
-
Save 0GiS0/151eee3d5190a7d0b380421d246c6916 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Controller; | |
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | |
use Symfony\Component\Cache\Adapter\AdapterInterface; | |
use Symfony\Component\Routing\Annotation\Route; | |
class HomeController extends AbstractController | |
{ | |
private $cache; | |
public function __construct(AdapterInterface $cacheClient) | |
{ | |
$this->cache = $cacheClient; | |
} | |
/** | |
* @Route("/", name="home") | |
*/ | |
public function index() | |
{ | |
$itemCache = $this->cache->getItem('cached'); | |
$cached = 'no'; | |
if (!$itemCache->isHit()) { | |
$itemCache->set('yes'); | |
$this->cache->save($itemCache); | |
} else { | |
$cached = $itemCache->get(); | |
} | |
return $this->render('home/index.html.twig', [ | |
'controller_name' => 'HomeController', | |
'cached' => $cached, | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment