deniztezcan/laravel-responsecache-additions

Speed up a Laravel application by caching the entire response additions

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

This package is auto-updated.

Last update: 2024-04-11 13:58:27 UTC


README

Latest Version on Packagist MIT Licensed Total Downloads

Additions to Spatie's speed up a Laravel app by caching the entire response package so that Mobile and Desktop visitors view different websites.

Installation

You can install the package via composer:

composer require deniztezcan/laravel-responsecache-additions

The package will automatically register itself.

You can publish the config file with:

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

Replace the following line

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

with

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

This will make sure Mobile and Desktop visitors view different websites. If you want to make sure a specific area of the website get's replaced by a live version please change:

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

with your own replacer, for instance located in App\Replacers\FooReplacer

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

The FooReplacer can consists of the following

<?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
}

this will replace the content of the with the on load view renderings of the file partials.fake-blade-loc.