Browse Source

Cache control

dev-master
Simon Vieille 2 years ago
parent
commit
2ac9737409
No known key found for this signature in database GPG Key ID: 919533E2B946EA10
6 changed files with 21 additions and 13 deletions
  1. +1
    -0
      app/bootstrap.php.d/80-cache.php
  2. +6
    -2
      src/Gist/Controller/Controller.php
  3. +3
    -2
      src/Gist/Controller/EditController.php
  4. +2
    -2
      src/Gist/Controller/LoginController.php
  5. +2
    -1
      src/Gist/Controller/MyController.php
  6. +7
    -6
      src/Gist/Controller/ViewController.php

+ 1
- 0
app/bootstrap.php.d/80-cache.php View File

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

+ 6
- 2
src/Gist/Controller/Controller.php View File

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


+ 3
- 2
src/Gist/Controller/EditController.php View File

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


+ 2
- 2
src/Gist/Controller/LoginController.php View File

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


+ 2
- 1
src/Gist/Controller/MyController.php View File

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


+ 7
- 6
src/Gist/Controller/ViewController.php View File

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


Loading…
Cancel
Save