deniztezcan/laravel-responsecache-additions

通过缓存整个响应附加内容来加速 Laravel 应用程序

v1.0.3 2022-01-11 08:41 UTC

This package is auto-updated.

Last update: 2024-09-11 15:03:48 UTC


README

Latest Version on Packagist MIT Licensed Total Downloads

通过缓存整个响应包来加速 Spatie 的 Laravel 应用程序,以便移动和桌面访客查看不同的网站。

安装

您可以通过 composer 安装此包

composer require deniztezcan/laravel-responsecache-additions

该包将自动注册自己。

您可以使用以下命令发布配置文件:

php artisan vendor:publish --provider="Spatie\ResponseCache\ResponseCacheServiceProvider"

替换以下行

'hasher' => \Spatie\ResponseCache\Hasher\DefaultHasher::class,

'hasher' => \DenizTezcan\ResponseCache\Hasher\MobileHasher::class,

这将确保移动和桌面访客查看不同的网站。如果您想确保网站的具体区域被实时版本替换,请将

'replacers' => [
    \Spatie\ResponseCache\Replacers\CsrfTokenReplacer::class,
],

替换为您自己的替换器,例如位于 App\Replacers\FooReplacer

'replacers' => [
    \Spatie\ResponseCache\Replacers\CsrfTokenReplacer::class,
    \App\Replacers\FooReplacer::class,
],

FooReplacer 可以包含以下内容

<?php

namespace App\Replacers;

use DenizTezcan\ResponseCache\Replacers\BladeFilesReplacer;

class FooReplacer extends BladeFilesReplacer
{
	protected string | array $htmlTag = 'fake-html-tag'; // html tag without the <> in string or array format
    protected string | array $realTimeView = 'partials.fake-blade-loc'; // blade path string or array format
}

这将替换文件 partials.fake-blade-loc 在加载视图渲染时的内容。