tsaiyihua/laravel-pagecache
Composer 安装命令:
composer require tsaiyihua/laravel-pagecache
包简介
Page Cache for Laravel
关键字:
README 文档
README
This Package is mainly used as a cached content on the entire page.
If you had the low hit rate cache on your web page, this package will help you to solve this problem.
Basic Concept
- When the accessed web page does not have cached content, the program content is directly executed, and the execution program that generates the physical webpage file is thrown into the queue to execute.
- When the accessed web page has cached content, the cached content display is directly read.
- When the accessed webpage has cached content, but the file generation time exceeds the set expiration time, the cache content display is directly read first, and then the execution program that generates the physical webpage file is thrown into the queue for execution.
Laravel Support
| Version | Laravel Version |
|---|---|
| 1.0.x | 5.6, 5.7, 5.8 |
| 1.1.x | 6.x |
| 2.x | 7.x, 8.x, 9.x, 10.x |
Install
composer require tsaiyihua/laravel-pagecachephp artisan vendor:publish --tag=pagecache- Add disk to config/filesystems.php
'pages' => [ 'driver' => 'local', 'root' => env('PAGE_CACHE_DISK', storage_path('app/pages')), ],
- Add middleware to $routeMiddleware in app/Http/kernel.php
'pageCache' => \TsaiYiHua\Cache\Http\Middleware\PageCache::class
- Create temporary folder, suppose that you use the default setting in Laravel
cd {YOUR PROJECT FOLDER}
mkdir storage/app/pages
chmod 777 storage/app/pages
- And then add "pageCache" middleware to your route where you want to cache page
OK, It's done. Join it.
.env variable descriptions
PAGE_CACHE_ENABLE=true PAGE_CACHE_ALIVE=1296000 PAGE_CACHE_URL_PATTERN=/^(http.*)\/\/([^\/]+)[\/]?([^\?]+)?\??(.*)?/ PAGE_CACHE_PARAMS=l,p PAGE_CACHE_DELAY=30 PAGE_CACHE_OWNER=nobody PAGE_CACHE_GROUP=nobody
- PAGE_CACHE_ENABLE boolean, page cache will work while this value is true
- PAGE_CACHE_ALIVE timestamp, Page cache alive time, default is 15 days
- PAGE_CACHE_URL_PATTERN regular expression, the default is common used, if you has the special rule, change this value.
- PAGE_CACHE_PARAMS the query string who want to be cached, separate by ','
- PAGE_CACHE_DISK The page cache file storage, if you use the default setting, don't set this variable in .env
- PAGE_CACHE_DELAY seconds, Create cache file after the page visited
- PAGE_CACHE_OWNER The page cache file owner. only used while manage the cache file
- PAGE_CACHE_GROUP The page cache file group. only used while manage the cache file
If you use the Cloud Storage, just ignore the PAGE_CACHE_OWNER and PAGE_CACHE_GROUP
APP_ENV in .env
- While APP_ENV is "production", the request parameter "noCache" will be set as false to avoid slow the online version.
- Base on the above reason
- We suggest you have more than 2 servers, the APP_ENV on online version can be set as "production", and one of the servers can be set other word except "production" to generator the cache file.
- If you have only one server, the APP_ENV can not be production.
- The cache generator server must edit /etc/hosts, and add the domain ip to 127.0.0.1
Commands
php artisan pagecache:clear
Clear all page cache, if there had the permission problem, just use sudo to execute.php artisan pagecache:refresh {url}
Refresh the page cache by URL.php artisan pagecache:info {url}
Get the page cache info by URLphp artisan pagecache:info stat {--date= : stat date}
If the {url} is state, it will show the stat info, the default date is today, you can use --date= to specify the date, format is Ymd.
tsaiyihua/laravel-pagecache 适用场景与选型建议
tsaiyihua/laravel-pagecache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.27k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 12 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「page」 「cache」 「laravel」 「pagecache」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tsaiyihua/laravel-pagecache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tsaiyihua/laravel-pagecache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tsaiyihua/laravel-pagecache 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
DataTables is a plug-in for the jQuery Javascript library. It is a highly flexible tool, based upon the foundations of progressive enhancement, which will add advanced interaction controls to any HTML table.
repository php library
Plug-ins for DataTables
This package helps you use bitwise enums in PHP and Laravel.
Laravel 5 - Repositories to the database layer
Rinvex Repository is a simple, intuitive, and smart implementation of Active Repository with extremely flexible & granular caching system for Laravel, used to abstract the data layer, making applications more flexible to maintain.
统计信息
- 总下载量: 4.27k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-12-11