PHP code example of switon / http-cache
1. Go to this page and download the library: Download switon/http-cache 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/ */
switon / http-cache example snippets
use Switon\Http\RequestInterface;
use Switon\HttpCache\Attribute\PageCache;
use Switon\Routing\Attribute\GetMapping;
class ProductController
{
#[GetMapping('/products')]
#[PageCache(ttl: 600, key: ['category', 'page'])]
public function listAction(RequestInterface $request): array
{
$category = $request->get('category', 'all');
$page = (int)$request->get('page', 1);
return [
'category' => $category,
'page' => $page,
'items' => $this->loadProducts($category, $page),
];
}
}