HTTP Cache

This commit is contained in:
Simon Vieille 2018-08-20 16:40:04 +02:00
parent 2d8f19437a
commit b7e6d8c69c
No known key found for this signature in database
GPG Key ID: 919533E2B946EA10
6 changed files with 20 additions and 3 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@
/app/config/propel/
/data/
/trans/
/cache/

View File

@ -26,6 +26,7 @@ update:
$(GIT) pull origin master
${MKDIR} -p data/git
${MKDIR} -p data/cache
$(COMPOSER) update
$(NPM) install

View File

@ -0,0 +1,7 @@
<?php
use Silex\Provider\HttpCacheServiceProvider;
$app->register(new HttpCacheServiceProvider(), array(
'http_cache.cache_dir' => $app['root_path'].'/cache/',
));

View File

@ -175,9 +175,17 @@ abstract class Controller
$params['user'] = $this->getUser();
}
return $app['twig']->render(
$body = $app['twig']->render(
$template,
$params
);
$response = new Response($body);
if (empty($params['no_cache'])) {
$response->setTtl(3600 * 24 * 7);
}
return $response;
}
}

View File

@ -4,4 +4,4 @@ $app = require __DIR__.'/../app/bootstrap.php';
$app['env'] = 'prod';
$app->run();
$app['http_cache']->run();