mothership/headless-shopware-varnish-cache 问题修复 & 功能扩展

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

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

mothership/headless-shopware-varnish-cache

Composer 安装命令:

composer require mothership/headless-shopware-varnish-cache

包简介

Shopware bundle that adds a cache adapter for a varnish for headless shopware

README 文档

README

This Shopware bundle adds a cache adapter for a varnish for headless shopware.
If activated, it automatically invalidates a varnish cache when a cache-tag gets invalidated in Shopware. Like this, an external frontend application can use an effective full page cache (FPC) together with a headless Shopware backend.

This bundle is meant to be used together with the corresponding nuxt module e.g. for Shopware-PWA. Nevertheless, it can be used without the nuxt module, if the headless application sets cache tags in another way.

This currently obviously only works on self-hosted Shopware instances, as you need to be able to install the bundle.

Installation

Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.

Applications that use Symfony Flex

Open a command console, enter your project directory and execute:

$ composer require mothership/headless-shopware-varnish-cache

Applications that don't use Symfony Flex

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require mothership/headless-shopware-varnish-cache

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:

// config/bundles.php

return [
    // ...
    Mothership\HeadlessShopwareVarnishCacheBundle\HeadlessShopwareVarnishCacheBundle::class => ['all' => true],
];

Step 3: Configuration

First add the configuration file:

# www/config/packages/cache.yml
headless_shopware_varnish_cache:
  enabled: "%env(bool:HEADLESS_VARNISH_ACTIVE)%"
  reverse_proxy:
    hosts: "%env(csv:HEADLESS_VARNISH_HOSTS)%"
    max_parallel_invalidations: 3
    ban_method: "BAN"
    tag_flush_threshold: 100
    use_xkey: true # requires Varnish module xkey
    xkey_chunksize: 50 # optional, default: 50

As you can see, two environment variables are used:

Example Varnish configuration

See a stripped down example Varnish configuration here.
There is also an example available which only uses xkeys here.

Disclaimer: this is not a production ready configuration file and stripped down to show the essential parts for the caching solution!

Usage

After installation and activation the module automatically invalidates the varnish cache at the configured hosts when a cache-tag gets invalidated in Shopware.
For example if a product changes, Shopware by default invalidates a cache-tag for this product. Like this all pages that contain this product get invalidated too and therefore are always up-to-date.

CLI-Command to manually flush the cache

bin/console varnish:invalidate

  • by default, it flushes the whole cache for all hosts
  • --tags : Comma separated tags to clear
  • --regex : Regex to match URLs which should be flushed

Flush manually via curl

Using the xkeys version

Usecase Command Description
single URL curl -X BAN https://www.domain.de/my/path Only the specified URL gets flushed
whole domain curl -X BAN -H 'xkey: all' https://www.domain.de Flush all URLs on the specified host
single cache-tag curl -X BAN -H 'xkey: product-<ID>' https://www.domain.de Flush all sites (on all hosts) with cache-tag "product-"

Using the custom-header version

Usecase Command Description
single URL curl -X BAN https://www.domain.de/my/path Only the specified URL gets flushed
whole host curl -X BAN -H 'X-Cache-Tags: all' https://www.domain.de Flush all URLs on the specified host
single cache-tag curl -X BAN -H 'X-Cache-Tags: product-<ID>' https://www.domain.de Flush all sites with cache-tag "product-" on this host

mothership/headless-shopware-varnish-cache 适用场景与选型建议

mothership/headless-shopware-varnish-cache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.81k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2022 年 10 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 mothership/headless-shopware-varnish-cache 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 7
  • Watchers: 5
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-20