Closed borgogelli closed 5 months ago
This package and Twig's caching are complementary and serve different purposes but they can also be used together.
Slim-HttpCache is a middleware for HTTP caching. It handles caching at the HTTP level. This middleware uses cache-related HTTP headers such as Cache-Control
, ETag
, and Last-Modified
to manage client-side and intermediary caches.
Twig's caching, on the other hand, is about caching the compiled template code. This reduces the overhead of compiling templates every time they are rendered.
Simple example (not tested)
$app->get('/', function (Request $request, Response $response, $args) use ($twig) {
// Set Cache-Control and other HTTP cache headers
$cacheProvider = new CacheProvider();
$response = $cacheProvider->withExpires($response, time() + 3600);
$response = $cacheProvider->withEtag($response, md5('home-page'));
// Render template with Twig
return $twig->render($response, 'home.twig');
});
Hello
Does "Slim-HttpCache" integrate with the twig cache or is an alternative to it ?
Thank you
Andrea