HTTP Cache

This commit is contained in:
Simon Vieille 2018-08-20 16:40:04 +02:00
父節點 2d8f19437a
當前提交 b7e6d8c69c
沒有發現已知的金鑰在資料庫的簽署中
GPG Key ID: 919533E2B946EA10
共有 6 個文件被更改,包括 20 次插入3 次删除

1
.gitignore vendored
查看文件

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

查看文件

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

查看文件

@ -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;
});

查看文件

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

查看文件

@ -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;
}
}

查看文件

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