I'd like my symfony application to use the symfony internal reverse proxy. This is really easy:
# config/packages/framework.yaml
framework:
http_cache:
enabled: true
debug: true
trace_level: 'full'
// src/Controller/MyController.php
final class MyController
{
#[Route('/articles', name: 'articles')]
#[Cache(public: true, mustRevalidate: true, expires: 'tomorrow')]
public function test(Request $request, TagAwareCacheInterface $cache, Environment $twig): Response
{
$page = $request->query->get('page', 1);
$item = $cache->get("articles-page-{$page}", function(ItemInterface $item) use ($page, $twig) {
if ($item->isHit()) {
return $item->get();
}
// expensive algorithm to calculate $content variable
// ...
$item->set($content);
return $item->get();
});
return new Response($item);
}
So far so good, I now have this controller cached correctly into my filesystem.
I wanted my new http cache system to store exclusively into a redis server. So I added this:
# config/packages/cache.yaml
framework:
cache:
app: cache.adapter.redis
default_redis_provider: redis://redis:6379
This does not work as expected as it sets both my redis and the filesystem caches.
When I empty my redis, reloading my url proves that my application uses the filesystem as http cache too.
// public/index.php
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
return function (array $context) {
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
$cacheKernel = new Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache($kernel);
return $cacheKernel;
};
How do I do to only have the redis store for the http cache ?
Env:
"symfony/framework-bundle": "^6.1"
"predis/predis": "^2.0"