Browse Source

HTTP Cache

tags/v1.10.0
Simon Vieille 1 year ago
parent
commit
b7e6d8c69c
No known key found for this signature in database
6 changed files with 20 additions and 3 deletions
  1. +1
    -0
      .gitignore
  2. +1
    -0
      Makefile
  3. +1
    -1
      app/bootstrap.php.d/20-twig.php
  4. +7
    -0
      app/bootstrap.php.d/80-cache.php
  5. +9
    -1
      src/Gist/Controller/Controller.php
  6. +1
    -1
      web/index.php

+ 1
- 0
.gitignore View File

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

+ 1
- 0
Makefile View File

@@ -26,6 +26,7 @@ update:

$(GIT) pull origin master
${MKDIR} -p data/git
${MKDIR} -p data/cache
$(COMPOSER) update
$(NPM) install


+ 1
- 1
app/bootstrap.php.d/20-twig.php View File

@@ -9,6 +9,6 @@ $app->register(new TwigServiceProvider(), array(
$app->extend('twig', function ($twig, $app) {
$base = str_replace($app['request']->server->get('SCRIPT_NAME'), '', $app['request']->getBaseUrl());
$twig->addGlobal('web_path', $base.'/');
return $twig;
});

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

@@ -0,0 +1,7 @@
<?php

use Silex\Provider\HttpCacheServiceProvider;

$app->register(new HttpCacheServiceProvider(), array(
'http_cache.cache_dir' => $app['root_path'].'/cache/',
));

+ 9
- 1
src/Gist/Controller/Controller.php 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;
}
}

+ 1
- 1
web/index.php View File

@@ -4,4 +4,4 @@ $app = require __DIR__.'/../app/bootstrap.php';

$app['env'] = 'prod';

$app->run();
$app['http_cache']->run();

Loading…
Cancel
Save