perf(2meet-data-optimizer-hivepress-addon): expire object-cache transients

- with an external object cache, a HivePress timeout entry expires when it
  records; the value (written before its timeout) after at most a week — a
  miss only makes HivePress rebuild it. Entries of deleted posts no longer
  accumulate without end
- Verify: HivepressTransientFilterTest TTL test, integration 53, unit 145;
  dev36 Redis TTL on tmdo_hp_transient keys
- PR: PR-099
This commit is contained in:
2026-09-27 16:42:52 +08:00
parent f06a80eae5
commit d129139c7d
3 changed files with 37 additions and 3 deletions
@@ -80,6 +80,9 @@ final class TMDO_Hivepress_Transient_Filter {
/** Object cache group used instead of wp_options when a persistent cache is present. */
public const CACHE_GROUP = 'tmdo_hp_transient';
/** Longest an object-cache entry lives: a week (HivePress's default is a day). */
public const MAX_CACHE_TTL = 604800;
/**
* Register the four metadata filters on `init`. Idempotent — safe to call
* multiple times.
@@ -267,8 +270,10 @@ final class TMDO_Hivepress_Transient_Filter {
* In wp_options both halves of the transient pair are written with
* `autoload=no` (they are read on-demand only — never via
* wp_load_alloptions() — so eagerly loading them on every page would defeat
* the point of the move). HivePress checks the timeout itself, so the
* cache entries get no TTL of their own.
* the point of the move). In the object cache a timeout entry expires when
* it says; the value, written before its timeout, after MAX_CACHE_TTL — a
* miss only makes HivePress rebuild it — so entries of deleted posts do
* not pile up (2.3 PR-099).
*
* @param int $post_id Post ID.
* @param string $meta_key Original `_transient_*` meta_key.
@@ -281,7 +286,8 @@ final class TMDO_Hivepress_Transient_Filter {
$option_name = ( $is_timeout ? '_transient_timeout_' : '_transient_' ) . $translated;
if ( wp_using_ext_object_cache() ) {
wp_cache_set( $option_name, $meta_value, self::CACHE_GROUP );
$ttl = $is_timeout ? min( self::MAX_CACHE_TTL, max( 1, (int) $meta_value - time() ) ) : self::MAX_CACHE_TTL;
wp_cache_set( $option_name, $meta_value, self::CACHE_GROUP, $ttl );
return;
}
update_option( $option_name, $meta_value, false );