yurikzt/html-cache-page-bundle
Composer 安装命令:
composer require yurikzt/html-cache-page-bundle
包简介
Symfony bundle for caching HTML pages to files
README 文档
README
Symfony bundle for caching HTML, JSON, and XML responses as static files. Supports flexible rule-based configuration, auto-cleaning, and CLI tools.
📦 Installation
composer require yurikzt/html-cache-page-bundle
⚙️ Configuration
After installation, create a config file: config/packages/html_cache_page.yaml
html_cache_page: enabled: true ttl: 3600 cache_dir: '%kernel.project_dir%/public/cache' cacheable_content_types: - 'text/html' - 'application/json' - 'application/xml' - 'text/xml' cache_rules: - pattern: '/blog/*' methods: ['GET'] - pattern: '#^/api/products/\d+$#' methods: ['GET'] parameters: format: ['json', 'xml'] exclude_rules: - pattern: '/admin/*' - pattern: '/api/auth/*' logging: enabled: true driver: symfony logger_service: null
🚀 Usage
Automatic Caching
All HTTP 200 responses that match the cache rules will be saved as files.
Clearing Cache Programmatically
use Yurikzt\HtmlCachePageBundle\Service\CacheCleaner; class MyController { public function __construct(private CacheCleaner $cacheCleaner) {} public function clearCache(): JsonResponse { $this->cacheCleaner->clearAll(); $this->cacheCleaner->clearByPattern('/blog/*'); $this->cacheCleaner->clearByUrl('/blog/my-post'); $this->cacheCleaner->clearExpired(); $stats = $this->cacheCleaner->getStats(); return new JsonResponse(['stats' => $stats]); } }
Console Commands
bin/console html-cache-page:clear --stats bin/console html-cache-page:clear bin/console html-cache-page:clear "/blog/*" bin/console html-cache-page:clear "#^/product/\d+$#" bin/console html-cache-page:clear --url="/blog/abc" bin/console html-cache-page:clear --expired
🗂 Cache File Structure
/blog/post-1→public/cache/blog/post-1/index.html/→public/cache/index.html/api/products/1.json→public/cache/api/products/1.json- Metadata:
.metafile alongside each cache file.
{
"created_at": 1640995200,
"ttl": 3600,
"content_type": "text/html",
"status_code": 200
}
🧠 Rule Options
Pattern Types
- Wildcard:
/blog/* - Regex:
#^/product/\d+$#
Query Parameters
parameters: q: true category: false sort: ['name', 'date'] limit: '10'
📥 HTTP Headers
Bundle adds a header: X-Cache-Status: HIT|MISS
📁 Web Server Configuration
✅ Nginx
location ~* ^/cache/(.*)$ { try_files $uri =404; access_log off; expires 1h; } location / { try_files $uri $uri/ @cached; } location @cached { set $cached_file "/cache$uri/index.html"; if (!-f $document_root$cached_file) { set $cached_file "/cache$uri"; } try_files $cached_file @symfony; } location @symfony { try_files /index.php =404; } location ~ \.php$ { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param HTTPS off; }
✅ Apache
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^ - [L] RewriteCond %{DOCUMENT_ROOT}/cache%{REQUEST_URI}/index.html -f RewriteRule ^ cache%{REQUEST_URI}/index.html [L] RewriteCond %{DOCUMENT_ROOT}/cache%{REQUEST_URI} -f RewriteRule ^ cache%{REQUEST_URI} [L] RewriteRule ^ index.php [L] </IfModule>
✅ Requirements
- PHP 8.1+
- Symfony 6.0+
📄 License
MIT
yurikzt/html-cache-page-bundle 适用场景与选型建议
yurikzt/html-cache-page-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 yurikzt/html-cache-page-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yurikzt/html-cache-page-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-11