在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):barryvdh/laravel-httpcache开源软件地址(OpenSource Url):https://github.com/barryvdh/laravel-httpcache开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):HttpCache for LaravelLaravel can use HttpKernelInterface Middlewares, so also HttpCache. This package provides a simple ServiceProvider to get you started with HttpCache. First, require this package with composer
After updating, add the ServiceProvider to the array of providers in app/config/app.php
You can now add the Middleware to your Kernel:
Caching is now enabled, for public responses. Just set the Ttl or MaxSharedAge Route::get('my-page', function(){
return Response::make('Hello!')->setTtl(60); // Cache 1 minute
}); You can use the provided protected $routeMiddleware = [
// ...
'ttl' => \Barryvdh\HttpCache\Middleware\SetTtl::class,
];
Route::get('my-page', function(){
return 'Hello'
})->middleware('ttl:60'); // Cache 1 minute Publish the config to change some options (cache dir, default ttl, etc) or enable ESI.
Direct approach, without ServiceProvider
You can also wrap the Kernel in the HttpCache, in your public/index.php. Replace the 'Run The Application' part like this:
ESIEnable ESI in your config file and add the Esi Middleware to your Kernel:
You can now define ESI includes in your layouts.
This will render partial/page, with it's own TTL. The rest of the page will remain cached (using it's own TTL) Purging/flushing the cacheYou can purge a single url or just delete the entire cache directory: App::make('http_cache.store')->purge($url);
\File::cleanDirectory(app('http_cache.cache_dir')); Or use the Artisan
More informationFor more information, read the Docs on Symfony HttpCache |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论