tsaiyihua/laravel-pagecache 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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-pagecache
  • php 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 URL
  • php 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 tsaiyihua/laravel-pagecache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4.27k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-12-11