imagina / ihelpers-module
10.0.0
2024-06-11 20:56 UTC
Requires
- php: ^8.1
- composer/installers: ~1.0
- imagina/core-module: ^10.0
Requires (Dev)
- orchestra/testbench: ^8.5
- phpunit/phpunit: ^10
README
基于: https://github.com/spatie/laravel-responsecache/tree/v1 https://github.com/JosephSilber/page-cache (用于文件缓存重定向)
激活缓存系统
修改
// config/app.php 'providers' => [ ... Modules\Ihelpers\Other\ImResponseCache\ImResponseCacheServiceProvider::class, ];
此包还包含一个门面。
// config/app.php 'aliases' => [ ... 'ResponseCache' => Modules\Ihelpers\Other\ImResponseCache::class, ];
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Modules\Ihelpers\Other\ImResponseCache\ImResponseCacheServiceProvider"
可用于清除缓存的命令
php artisan pagecache:clear
URL重写
为了在文件被缓存后直接服务静态文件,您需要正确配置您的Web服务器以检查这些静态文件。
-
对于nginx
更新您的
location
块的try_files
指令以包括对page-cache
目录的检查location / { try_files $uri $uri/ /page-cache/$uri.html /index.php?$query_string; }
-
对于apache
打开
public/.htaccess
并在标签为Handle Front Controller
的块之前添加以下内容# Serve Cached Page If Available... RewriteCond %{REQUEST_URI} ^/?$ RewriteCond %{DOCUMENT_ROOT}/page-cache/pc__index__pc.html -f RewriteRule .? page-cache/pc__index__pc.html [L] RewriteCond %{DOCUMENT_ROOT}/page-cache%{REQUEST_URI}%{QUERY_STRING}.html -f RewriteRule . page-cache%{REQUEST_URI}.html [L]
自定义包含和关系功能
您可以在任何模块的任何实体中设置自定义包含和关系,如下所示
-
在
Modules\Imodule\Config\config.php
'includes'=>[ 'EntityTransformer'=>[ 'otherEntity'=>[ 'path'=>'Modules\Iothermodule\Transformers\OtherEntityTransformer', //this is the transformer path 'multiple'=>false, //if the relationship is one-to-many, multiple must be set to true ], ], ... ], 'relations' =>[ 'entity'=>[ 'otherEntity' => function () { return $this->hasOne( \Modules\Iothermodule\Entities\OtherEntity::class, 'model_id'); }, ], ... ],
-
在
Modules\Imodule\Entities\Entity.php
您必须使用以下特性来使用自定义关系
use Modules\Ihelpers\Traits\Relationable; class Entity extends Model{ use Relationable;
-
在
Modules\Imodule\Transformers\EntityTransformer.php
您必须使用以下特性来使用自定义包含
use Modules\Ihelpers\Traits\Transformeable; class EntityTransformer extends JsonResource{ use Transformeable;