boangri/magento2-module-cybercache 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

boangri/magento2-module-cybercache

Composer 安装命令:

composer require boangri/magento2-module-cybercache

包简介

Generic and page cache backend using CyberCache Cluster

README 文档

README

The extension consists of two separate modules: default cache/FPC store, and session store.

  1. Default Cache and FPC Store

To make Magento use CyberCache as its default cache as well as FPC store, it is necessary to do the following:

1.1) Copy Extension Files

Copy all the files from the directory where this readme.md file is located, as well as all its subdirectories, to

<Magento-installation-directory>/app/code/CyberHULL/CyberCache/

If there was previous version of the CyberCache extension installed at that location, you may want to delete old files before copying new.

IMPORTANT: files must be readable by Magento code! For Apache server to be able to access them, change group owner to www-data.

After installing the module, it can be enabled in Magento as described in the Magento documentation, but that is optional: CyberCache extension will work even without that. The "component name" of the extension (in case you choose to enable it) is CyberHULL_CyberCache; see etc/module.xml.

1.2) Modify composer.json

Add the following subsection to the "autoload" section of the composer.json file located in Magento installation directory:

"classmap": [
    "app/code/CyberHULL/CyberCache/src/C3"
],

If "classmap" section already exists, just add "app/code/CyberHULL/CyberCache/src/C3" to its end (individual records has to be separated with commas).

1.3) Update Autoload Map

From the Magento installation directory, execute the following command (as magento user!):

composer dump-autoload

If composer application has not been installed, one can either

  1. install it using sudo apt install composer (on Debian-based systems), or

  2. use one shipped with Magento; in this case, composer has to be run as

    php vendor/composer/composer/bin/composer dump-autoload

The result can be checked by searching vendor/composer/autoload_map.php for the C3_Store_CyberCacheStore string; if it exists as a key in the return array, then composer has re-configured Magento successfully.

1.4) Configure Magento Environment

Add the following sections to the app/etc/env.php file (or, if cache entry already exists in the return array, it has to be completely replaced with the below value):

'cache' =>
array(
  'frontend' =>
  array(
    'default' =>
    array(
      'backend' => 'C3_Store_CyberCacheStore',
      'backend_options' =>
      array( // missing entries will get default values
        'address' => '127.0.0.1',  // connection address; might be an internet address, or an IP
        'port' => '8120',          // connection port
        'persistent' => 'true',    // whether to use persistent connections (must match server settings)
        'hasher' => 'murmurhash2', // hash method to use for passwords
        'admin' => '',             // password for administrative commands
        'user' => '',              // password for user-level commands
        'compressor' => 'snappy',  // *initial* compressor for various data buffers
        'threshold' => '2048',     // minimal size of the buffer to compress
        'marker' => 'true'         // whether to use integrity check marker
      ),
    ),
    'page_cache' =>
    array(
      'backend' => 'C3_Store_CyberCacheStore',
      'backend_options' =>
      array( // missing entries will get default values
        'address' => '127.0.0.1',  // connection address; might be an internet address, or an IP
        'port' => '8120',          // connection port
        'persistent' => 'true',    // whether to use persistent connections (must match server settings)
        'hasher' => 'murmurhash2', // hash method to use for passwords
        'admin' => '',             // password for administrative commands
        'user' => '',              // password for user-level commands
        'compressor' => 'snappy',  // *initial* compressor for FPC data buffers
        'threshold' => '2048',     // minimal size of the buffer to compress
        'marker' => 'true'         // whether to use integrity check marker
      )
    )
  )
),

After the above four steps, Magento 2 will run with CyberCache being its default and Full Page cache.

  1. Session Store

Unlike general-purpose and full page cache handlers, session handlers are more deeply integrated into Magento 2, so it is necessary to patch some Magento core files to start using CyberCache as Magento session store.

Redis session extension was available for Magento 2 since very first releases, but it only became supported in version 2.0.6: because it was necessary to patch Magento itself.

To enable CyberCache as Magento 2 session store, it is necessary to do the following:

2.1) Copy Extension Files

See section 1.1, above.

2.2) Modify Core Magento Files

CyberCache extension does not require a class wrapper added to Magento core since its data-handling methods do not throw exceptions that would need to be caught (which is the case with ConcurrentConnectionsExceededException thrown by Redis extension, for example). Still, some changes have to be made.

NOTE: all code change instructions imply Magento 2.1.7. Line numbers may differ for other versions.

2.2.1) Add Session Saver Constant

Modify vendor/Magento/Framework/Config/ConfigOptionsListConstants.php: add const SESSION_SAVE_CYBERCACHE = 'cybercache'; on line 60.

2.2.2) Make Magento Recognize CyberCache as "User" Handler

Modify vendor/Magento/Framework/Session/SaveHandler.php: change line 154 from if ($saveHandler === 'db' || $saveHandler === 'redis') { to if ($saveHandler === 'db' || $saveHandler === 'redis' || $saveHandler === 'cybercache') {.

2.3) Modify composer.json

2.3.1) Add "psr-4" Record

Add the following line to "autoload":"psr-4" section of the composer.json located in Magento installation folder:

"C3\\": "app/code/CyberHULL/CyberCache/src/C3"

Individual entries in the "psr-4" section has to be separated with commas.

2.3.2) Add "psr-0" Record

Add the following line to "autoload":"psr-0" section of the composer.json located in Magento installation folder:

"C3\\Session\\CyberCacheSession": "app/code/CyberHULL/CyberCache/src/"

Individual entries in the "psr-0" section has to be separated with commas.

2.4) Update Autoload Map

Run the following command in the Magento root directory (as magento user!):

composer dump-autoload

See section 1.3, above, on how to install/use the composer.

Whether update was successful can be checked by searching autoload_classmap.php and autoload_namespaces.php files in vendor/composer directory for the string CyberCacheSession; additionally, CyberCache string has to be present in the autoload_psr4.php file (in the same directory).

2.5) Configure Dependencies

2.5.1) Modify app/etc/di.xml

Modify array of handlers in app/etc/di.xml by adding cybercache (the last <item> line in the below snippet):

<type name="Magento\Framework\Session\SaveHandlerFactory">
    <arguments>
        <argument name="handlers" xsi:type="array">
            <item name="db" xsi:type="string">Magento\Framework\Session\SaveHandler\DbTable</item>
            <item name="redis" xsi:type="string">Magento\Framework\Session\SaveHandler\Redis</item>
            <item name="cybercache" xsi:type="string">C3\Session\CyberCacheSession</item>
        </argument>
    </arguments>
</type>

2.5.1) Modify vendor/magento/magento2-base/app/etc

Modify array of handlers in vendor/magento/magento2-base/app/etc by adding cybercache (the last <item> line in the below snippet):

<type name="Magento\Framework\Session\SaveHandlerFactory">
    <arguments>
        <argument name="handlers" xsi:type="array">
            <item name="db" xsi:type="string">Magento\Framework\Session\SaveHandler\DbTable</item>
            <item name="redis" xsi:type="string">Magento\Framework\Session\SaveHandler\Redis</item>
            <item name="cybercache" xsi:type="string">C3\Session\CyberCacheSession</item>
        </argument>
    </arguments>
</type>

2.6) Re-compile DI Files

In Magento installation folder, execute the following command (as magento user!):

bin/magento setup:di:compile

Compilation should end with the Generated code and dependency injection configuration successfully. message.

2.7) Configure Magento Environment

Default Magento environment configuration located in app/etc/env.php contains the followin entry:

'session' => 
   array (
     'save' => 'files',
   ),

To configure CyberCache-based session store, the session section in app/etc/env.php has to be changed to the following:

'session' => 
   array (
   'save' => 'cybercache', // replaces 'files'
   'cybercache' => 
     array ( // missing entries will get default values (the array might as well be empty)
        'address' => '127.0.0.1',   // connection address; might be an internet address, or an IP
        'port' => '8120',           // connection port
        'persistent' => 'true',     // whether to use persistent connections (must match server settings)
        'hasher' => 'murmurhash2',  // hash method to use for passwords
        'admin' => '',              // password for administrative commands
        'user' => '',               // password for user-level commands
        'compressor' => 'snappy',   // *initial* compressor for various data buffers
        'threshold' => '2048',      // minimal size of the buffer to compress
        'marker' => 'true',         // whether to use integrity check marker
        'magento_lifetime' => 'all' // whether to honor lifetimes set in Magento
    )
),

After the above seven steps, Magento 2 will run with CyberCache being its session store.

boangri/magento2-module-cybercache 适用场景与选型建议

boangri/magento2-module-cybercache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 11 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 boangri/magento2-module-cybercache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 boangri/magento2-module-cybercache 我们能提供哪些服务?
定制开发 / 二次开发

基于 boangri/magento2-module-cybercache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: proprietary
  • 更新时间: 2019-11-07