承接 labor-digital/typo3-distributed-cache-clearing 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

labor-digital/typo3-distributed-cache-clearing

Composer 安装命令:

composer require labor-digital/typo3-distributed-cache-clearing

包简介

Handler to clear the cache in multi-container setups

README 文档

README

Utility extension to clear the local file caches in a multi-container setup. It is designed to be easily extendable with all kinds of message queue backends. By default a DB/TYPO3 Registry and Redis backend are included.

Requirements

Installation

Install this package using Composer:

composer require labor-digital/typo3-distributed-cache-clearing

Usage

To utilize the distributed cache clearing you need to register a backend class using the ext config logic. This will activate the message handling when the TYPO3 cache is cleared in the backend or though the CLI.

<?php

namespace LaborDigital\T3baExample\Configuration\ExtConfig;

use LaborDigital\T3ba\ExtConfig\ExtConfigContext;
use LaborDigital\T3dcc\Core\Message\Backend\Registry\RegistryMessageBackend;
use LaborDigital\T3dcc\ExtConfigHandler\ConfigureDistributedCacheClearingInterface;
use LaborDigital\T3dcc\ExtConfigHandler\DccConfigurator;

class Dcc implements ConfigureDistributedCacheClearingInterface
{
    public static function configureDistributedCacheClearing(DccConfigurator $configurator, ExtConfigContext $context): void
    {
        // You can use any of the built-in backends or a class that implements the MessageBackendInterface here.
        // Additional options for the backend can be provided as second parameter
        $configurator->setMessageBackend(RegistryMessageBackend::class);
    }
}

In order to listen for the cache cleared event emitted in another container you can use multiple approaches. The first one, which is the simplest to implement is by setting the "check in every request" option to true. It is also done in the ext config class. The major downside of this option is a potential dip in your performance, especially if external event queues (SNS, ServiceBus, ...) are used.

<?php

namespace LaborDigital\T3baExample\Configuration\ExtConfig;

use LaborDigital\T3ba\ExtConfig\ExtConfigContext;
use LaborDigital\T3dcc\Core\Message\Backend\Registry\RegistryMessageBackend;
use LaborDigital\T3dcc\ExtConfigHandler\ConfigureDistributedCacheClearingInterface;
use LaborDigital\T3dcc\ExtConfigHandler\DccConfigurator;

class Dcc implements ConfigureDistributedCacheClearingInterface
{
    public static function configureDistributedCacheClearing(DccConfigurator $configurator, ExtConfigContext $context): void
    {
        $configurator->setCheckInEveryRequest(true)
    }
}

If your infrastructure allows you to perform an HTTP request to EACH container independently, and you use the T3FA extension, you may use the DccBundle in your site routing configuration The route will be available at: /api/dcc/clearIfRequired.

<?php
namespace LaborDigital\T3baExample\Configuration\ExtConfig\Site\Common;

use LaborDigital\T3dcc\Api\Bundle\DccBundle;
use LaborDigital\T3fa\ExtConfigHandler\Api\BundleCollector;
use LaborDigital\T3fa\ExtConfigHandler\Api\ConfigureApiInterface;

class Api implements ConfigureApiInterface
{
    public static function registerBundles(BundleCollector $collector): void
    {
        $collector->register(DccBundle::class);
    }
    
    /* ... */
}

Alternatively you can use the built-in cli command t3dcc:handleMessages which does the same.

As as last resort for highly specialized setups you can use the /ext/t3dcc/handleMessages.php file provided by the extension. It can be executed in ANY other PHP script, even without TYPO3 context. It contains an encapsulated bootstrap and small application to boot up the TYPO3 core and flush the caches if needed. Before you can include the file you need to set T3DCC_AUTOLOAD_PATH either as environment variable, or constant to the absolute path to your composer autoload.php. The rest should work automatically.

This script would be located in the public/typo3conf directory of your installation.

<?php
define('T3DCC_AUTOLOAD_PATH', dirname(__DIR__, 2) . '/vendor/autoload.php');
require __DIR__ . '/ext/t3dcc/handleMessages.php';

Backends

The extension provides two simple backends:

RegistryMessageBackend

This backend utilizes the TYPO3 sys_registry table to send messages between the containers. It is the most simple implementation and does not require additional options or configuration.

RedisMessageBackend

This backend utilizes a Redis database as messaging queue between containers. The configuration follows the same structure as the redis cache backend.

<?php
namespace LaborDigital\T3baExample\Configuration\ExtConfig;

use LaborDigital\T3ba\ExtConfig\ExtConfigContext;
use LaborDigital\T3dcc\Core\Message\Backend\Redis\RedisMessageBackend;
use LaborDigital\T3dcc\ExtConfigHandler\ConfigureDistributedCacheClearingInterface;
use LaborDigital\T3dcc\ExtConfigHandler\DccConfigurator;

class Dcc implements ConfigureDistributedCacheClearingInterface
{
    public static function configureDistributedCacheClearing(DccConfigurator $configurator, ExtConfigContext $context): void
    {
        $configurator->setMessageBackend(
        RedisMessageBackend::class,
        [
            // Required
            'hostname' => 'host',
            // The following options are optional
            'password' => '', // Only needed if the host requires a password
            'database' => 1, // It is not required, but recommended to set a database id here (Default: 1),
            'port' => 6379,
            'ttl' => 60 * 15
        ]
        );
    }
}

Postcardware

You're free to use this package, but if it makes it to your production environment, we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: LABOR.digital - Fischtorplatz 21 - 55116 Mainz, Germany.

We publish all received postcards on our company website.

统计信息

  • 总下载量: 304
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2022-05-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固