luklewluk / supercache
Pimcore 的 Supercache 插件
1.1.0
2016-10-31 18:05 UTC
Requires
- pimcore/installer-plugin: >=1
- psr/log: ~1.0
This package is not auto-updated.
Last update: 2024-09-16 03:16:15 UTC
README
Pimcore 的静态页面和文件缓存系统。
安装
composer require luklewluk/supercache
您还需要更改您的重写配置
####Apache
通过添加以下行编辑您的 Pimcore .htaccess 文件
### >>>SUPERCACHE PLUGIN
RewriteCond %{REQUEST_METHOD} !^(GET|HEAD) [OR]
RewriteCond %{QUERY_STRING} !^$
RewriteRule . - [S=3]
RewriteCond %{DOCUMENT_ROOT}/plugins/Supercache/webcache/%{HTTP_HOST}/$1/index.html -f
RewriteRule ^(.*) %{DOCUMENT_ROOT}/plugins/Supercache/webcache/%{HTTP_HOST}/$1/index.html [L]
RewriteCond %{DOCUMENT_ROOT}/plugins/Supercache/webcache/%{HTTP_HOST}/$1/index.js -f
RewriteRule ^(.*) %{DOCUMENT_ROOT}/plugins/Supercache/webcache/%{HTTP_HOST}/$1/index.js [L]
RewriteCond %{DOCUMENT_ROOT}/plugins/Supercache/webcache/%{HTTP_HOST}/$1/index.bin -f
RewriteRule ^(.*) %{DOCUMENT_ROOT}/plugins/Supercache/webcache/%{HTTP_HOST}/$1/index.bin [L]
### <<<SUPERCACHE PLUGIN
它应该位于以下之后
# 禁止直接访问 Pimcore 内部数据(例如,配置文件等)
并在以下之前
# 基本 zend-framework 设置请参阅:http://framework.zend.com/manual/en/zend.controller.html
####Nginx
虚拟主机配置
替换
try_files $uri $uri/ /index.php?$args;
为
try_files /plugins/Supercache/webcache/$http_host/$request_uri/index.js /plugins/Supercache/webcache/$http_host/$request_uri/index.html $uri $uri/ /index.php?$args;
一些测试
简单的 Pimcore 博客和每页请求时间(TTFB)
-
Supercache - ~0.37ms
-
输出缓存 - ~31.5ms
-
Pimcore 无额外缓存 - ~79.5ms
缓存清理
目前任何更改都会清理缓存。这被认为是最好的解决方案,特别是如果某人想在具有许多对象-文档依赖关系的复杂网站上使用 Supercache。如果您想手动清理缓存,可以按照以下方法之一操作
- 清理“输出缓存”(自 Pimcore 4.0 起)
- 在管理面板中保存任何文档或对象。
- 删除 ./plugins/Supercache/webcache 中的所有内容,除了 .htaccess
自 Pimcore 4.0 起在维护模式激活时也会清理 Supercache。
问题
JSON 响应
注意:如果您想缓存 JSON 响应,这可能很有用。
由于 Pimcore/Zend 的良好实践,您应该使用以下命令通过助手将输出编码为 JSON
$this->_helper->json($json);
遗憾的是,您的响应将不会被缓存,因为关闭事件无法被调用。最简单的解决方案是将它替换为
echo $this->_helper->json($json, false);