定制 kodansha/wack-cloudfront-invalidation 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

kodansha/wack-cloudfront-invalidation

Composer 安装命令:

composer require kodansha/wack-cloudfront-invalidation

包简介

Invalidate CloudFront caches when a post is published or updated.

README 文档

README

WACK CloudFront Invalidation is a WordPress plugin that helps you to run invalidation on CloudFront after a post is published or updated.

It is designed to work with the WACK Stack, but can be used with any WordPress installation that uses CloudFront as a CDN.

How it works

This plugin triggers invalidation for published content updates by using:

  • save_post
  • rest_after_insert_{post_type} (for post and public custom post types)

It skips autosaves, revisions, and unpublished states such as draft and auto-draft.

Installation

  • Requires PHP 8.2 or later
  • Requires WordPress 6.7 or later
  • Requires Composer

Using Composer

composer require kodansha/wack-cloudfront-invalidation

Note

This plugin is not available on the WordPress.org plugin repository. The only installation method currently available is through Composer.

Configuration

AWS credentials

WACK CloudFront Invalidation uses AWS SDK for PHP to send invalidation requests to CloudFront, so you need to configure AWS credentials. Please refer to the AWS SDK for PHP documentation for more information on how to set up credentials.

CloudFront Distribution ID

You can configure a CloudFront Distribution ID in either of the following ways:

  1. Set WACK_CF_INV_DISTRIBUTION_ID in wp-config.php (or equivalent)
  2. Enter it in the plugin settings page (WACK Stack > WACK CF Inv)
define('WACK_CF_INV_DISTRIBUTION_ID', 'YOUR_CLOUDFRONT_DISTRIBUTION_ID');

Important

If WACK_CF_INV_DISTRIBUTION_ID is defined, it takes precedence over the value stored in the database.

Note

This plugin supports only one CloudFront Distribution ID.

Invalidation Path Settings

After installing the WACK CloudFront Invalidation plugin, a settings page is added to the WordPress admin menu under WACK Stack > WACK CF Inv.

In this settings page, you can configure CloudFront invalidation paths for each post type.

Important

To specify multiple paths, list them separated by line breaks. Empty lines will be ignored.

You can use the following placeholders in each path:

  • %id%: Replaced with the post ID
  • %slug%: Replaced with the post slug (falls back to post ID when slug is empty)

wack_cf_inv_{post_type}_paths filter

This plugin allows you to customize the CloudFront invalidation paths per post type using a filter.

The following filter is applied before issuing a CloudFront invalidation:

$paths = apply_filters('wack_cf_inv_' . $post->post_type . '_paths', $paths, $post);
  • {post_type}: Replace with your custom post type (e.g., post, news, etc.).
  • $paths: Array of paths determined by the post type and the plugin settings.
  • $post: The WP_Post object being processed.

Example

To add the homepage (/) to the invalidation paths for the post post type, add the following to your theme’s functions.php or a custom plugin:

add_filter('wack_cf_inv_post_paths', function($paths, $post) {
    $paths[] = '/';
    return $paths;
}, 10, 2);

This filter allows you to modify or extend the list of paths to be invalidated for each post type, providing flexible cache control.

Tip

If you want to modify or extend the list of paths for the news post type, use wack_cf_inv_news_paths instead of wack_cf_inv_post_paths.

Tips

WACK_CF_INV_DRY_RUN constant

Dry Run can be configured either by constant (WACK_CF_INV_DRY_RUN) or from the plugin settings page.

When WACK_CF_INV_DRY_RUN is defined, its value takes precedence over the database setting.

If Dry Run is enabled, the actual CloudFront invalidation execution will be skipped, and only log output will be performed.

You can use this for testing behavior in development environments.

WACK Log integration

If you have the WACK Log plugin installed, various logs from WACK CloudFront Invalidation will be output to standard output using WACK Log.

kodansha/wack-cloudfront-invalidation 适用场景与选型建议

kodansha/wack-cloudfront-invalidation 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 376 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「plugin」 「wordpress」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 kodansha/wack-cloudfront-invalidation 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2025-04-14