imagina/ihelpers-module

安装数: 1,828

依赖者: 11

建议者: 0

安全性: 0

星级: 1

关注者: 4

分支: 7

开放问题: 1

类型:asgard-module

10.0.0 2024-06-11 20:56 UTC

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;