1
0
mirror of https://gitnet.fr/deblan/gist.git synced 2021-08-14 08:30:49 +02:00

Cache control

This commit is contained in:
Simon Vieille 2018-08-20 17:05:36 +02:00
parent b7e6d8c69c
commit 2ac9737409
No known key found for this signature in database
GPG Key ID: 919533E2B946EA10
6 changed files with 21 additions and 13 deletions

View File

@ -4,4 +4,5 @@ use Silex\Provider\HttpCacheServiceProvider;
$app->register(new HttpCacheServiceProvider(), array( $app->register(new HttpCacheServiceProvider(), array(
'http_cache.cache_dir' => $app['root_path'].'/cache/', 'http_cache.cache_dir' => $app['root_path'].'/cache/',
'http_cache.esi' => null,
)); ));

View File

@ -136,7 +136,6 @@ abstract class Controller
$app = $this->getApp(); $app = $this->getApp();
if (!empty($request)) { if (!empty($request)) {
} }
$securityContext = $app['security.token_storage']; $securityContext = $app['security.token_storage'];
@ -160,10 +159,11 @@ abstract class Controller
* *
* @param string $template * @param string $template
* @param array $params * @param array $params
* @param bool $renderResponse
* *
* @return string * @return string
*/ */
public function render($template, array $params = null) public function render($template, array $params = null, $renderResponse = true)
{ {
$app = $this->getApp(); $app = $this->getApp();
@ -180,6 +180,10 @@ abstract class Controller
$params $params
); );
if (!$renderResponse) {
return $body;
}
$response = new Response($body); $response = new Response($body);
if (empty($params['no_cache'])) { if (empty($params['no_cache'])) {

View File

@ -9,6 +9,7 @@ use Gist\Model\Gist;
use GitWrapper\GitException; use GitWrapper\GitException;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Form\FormError; use Symfony\Component\Form\FormError;
use Symfony\Component\HttpFoundation\Response;
/** /**
* Class EditController. * Class EditController.
@ -22,7 +23,7 @@ class EditController extends Controller
* *
* @param Request $request * @param Request $request
* *
* @return string * @return Response
*/ */
public function createAction(Request $request) public function createAction(Request $request)
{ {
@ -68,7 +69,7 @@ class EditController extends Controller
* *
* @param Request $request * @param Request $request
* *
* @return string * @return Response
*/ */
public function cloneAction(Request $request, $gist, $commit) public function cloneAction(Request $request, $gist, $commit)
{ {

View File

@ -20,7 +20,7 @@ class LoginController extends Controller
* *
* @param Request $request * @param Request $request
* *
* @return string * @return Response
*/ */
public function registerAction(Request $request) public function registerAction(Request $request)
{ {
@ -72,7 +72,7 @@ class LoginController extends Controller
* *
* @param Request $request * @param Request $request
* *
* @return string * @return Response
*/ */
public function loginAction(Request $request) public function loginAction(Request $request)
{ {

View File

@ -7,6 +7,7 @@ use Gist\Form\DeleteGistForm;
use Gist\Form\FilterGistForm; use Gist\Form\FilterGistForm;
use Gist\Form\UserPasswordForm; use Gist\Form\UserPasswordForm;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
/** /**
* Class MyController. * Class MyController.
@ -21,7 +22,7 @@ class MyController extends Controller
* @param Request $request * @param Request $request
* @param int $page * @param int $page
* *
* @return string * @return Response
*/ */
public function myAction(Request $request, $page) public function myAction(Request $request, $page)
{ {

View File

@ -66,14 +66,14 @@ class ViewController extends Controller
* @param string $gist Gist's ID * @param string $gist Gist's ID
* @param string $commit The commit * @param string $commit The commit
* *
* @return string|Response * @return Response
*/ */
public function embedJsAction(Request $request, $gist, $commit) public function embedJsAction(Request $request, $gist, $commit)
{ {
$viewOptions = $this->getViewOptions($request, $gist, $commit); $viewOptions = $this->getViewOptions($request, $gist, $commit);
return new Response( return new Response(
$this->render('View/embedJs.html.twig', $viewOptions), $this->render('View/embedJs.html.twig', $viewOptions, false),
200, 200,
array( array(
'Content-Type' => 'text/javascript', 'Content-Type' => 'text/javascript',
@ -88,7 +88,7 @@ class ViewController extends Controller
* @param string $gist Gist's ID * @param string $gist Gist's ID
* @param string $commit The commit * @param string $commit The commit
* *
* @return string|Response * @return Response
*/ */
public function rawAction(Request $request, $gist, $commit) public function rawAction(Request $request, $gist, $commit)
{ {
@ -114,7 +114,7 @@ class ViewController extends Controller
* @param string $gist Gist's ID * @param string $gist Gist's ID
* @param string $commit The commit * @param string $commit The commit
* *
* @return string|Response * @return Response
*/ */
public function downloadAction(Request $request, $gist, $commit) public function downloadAction(Request $request, $gist, $commit)
{ {
@ -133,7 +133,8 @@ class ViewController extends Controller
'Content-Disposition' => sprintf('filename=%s.%s', $gist->getFile(), $gist->getTypeAsExtension()), 'Content-Disposition' => sprintf('filename=%s.%s', $gist->getFile(), $gist->getTypeAsExtension()),
'Content-Length' => mb_strlen($viewOptions['raw_content']), 'Content-Length' => mb_strlen($viewOptions['raw_content']),
'Content-Type' => 'application/force-download', 'Content-Type' => 'application/force-download',
) ),
false
); );
} else { } else {
return $this->notFoundResponse($app); return $this->notFoundResponse($app);
@ -146,7 +147,7 @@ class ViewController extends Controller
* @param Request $request * @param Request $request
* @param string $gist Gist's ID * @param string $gist Gist's ID
* *
* @return string|Response * @return Response
*/ */
public function revisionsAction(Request $request, $gist) public function revisionsAction(Request $request, $gist)
{ {