PHP code example of tugrul / http-cache-bundle
1. Go to this page and download the library: Download tugrul/http-cache-bundle library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tugrul / http-cache-bundle example snippets
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class BlogController extends AbstractController
{
public function index(): Response
{
$response = $this->render('blog/index.html.twig');
$response->setPublic();
$response->setMaxAge(3600); // Cache for 1 hour
return $response;
}
public function detail(string $slug): Response
{
$response = $this->render('blog/detail.html.twig', ['slug' => $slug]);
$response->setPublic();
$response->setMaxAge(3600);
return $response;
}
}