Download the PHP package label-li/laravel-page-cache without Composer
On this page you can find all versions of the php package label-li/laravel-page-cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download label-li/laravel-page-cache
More information about label-li/laravel-page-cache
Files in label-li/laravel-page-cache
Package laravel-page-cache
Short Description Page Cache for Laravel PHP Static Page
License MIT
Informations about the package laravel-page-cache
Laravel Page Cache
This package allows you to easily cache responses as static files on disk for lightning fast page loads.
- Introduction
- Installation
- Middleware
- Config
- Usage
- Credit
This package can cache static PHP page on local disk to provide a fast loading of pages
Introduction
It would be a heavy loading if lots of visitors plus the page loading lots of content from database with lots of logic Page cache can reduce the loading.
installation
1) Install package with composer:
2) Publish the config to config/pagecache.config
Middleware
If you want to cache all route in middleware
web
, i.e., all http traffics: 1) Openapp/Http/Kernel.php
2) Copy\LabelLi\LaravelPageCache\Middleware\CacheResponse::class,
as a new line to theweb
middleware group:If you want to cache specific route
page-cache
: 1) Openapp/Http/Kernel.php
2) Copy'page-cache' => \LabelLi\LaravelPageCache\Middleware\CacheResponse::class,
as a new line to the$routeMiddleware
:
Config
Change the value in config/pagecache.php
to what you want:
Usage
Using the middleware
If you choose to cache specific route, e.g.
page-cache
, use thepage-cache
middleware as follow:
/page
will be cached to a file under the storage/**$CachePath**
directory.
Clearing the cache
The cache will be cleared with the CacheTime
set in config/pagecache.php
.
It is default 3600s.
If you want to clear it manually, please run the following command
You may optionally pass a URL slug to the command, to only delete the cache for a specific page:
To clear everything under a given path, use the --recursive
flag:
Remark
If the Console function is not working, most likely to be the problem of permission for the cache folder.
Please check with ls -la
to check for the permission.
Credit
Thanks to Joseph Silber. The idea to run cache function directly at middleware is from his package. His package is very great but I have different usage. So I write another page cache package to archive my usage.