Skip to content

Commit

Permalink
Add default cache time constants and getter methods in WP 404 cache c…
Browse files Browse the repository at this point in the history
…lass

Added DEFAULT_CACHE_TIME and DEFAULT_STALE_CACHE_TIME constants to class-full-page-cache-404.php. Also introduced respective getter methods for each one of them: get_cache_time() and get_stale_cache_time(). Consequently updated the calls in set_cache() method to use these getters.
  • Loading branch information
attackant committed Mar 12, 2024
1 parent d63230e commit bd889f2
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/features/class-full-page-cache-404.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ final class Full_Page_Cache_404 implements Feature {
*/
public const STALE_CACHE_TIME = DAY_IN_SECONDS;

/**
* Cache time.
*
* @var int
*/
public const DEFAULT_CACHE_TIME = HOUR_IN_SECONDS;

/**
* Stale cache time.
*
* @var int
*/
public const DEFAULT_STALE_CACHE_TIME = DAY_IN_SECONDS;

/**
* Guaranteed 404 URI.
* Used for populating the cache.
Expand All @@ -67,6 +81,24 @@ final class Full_Page_Cache_404 implements Feature {
*/
public const TEMPLATE_GENERATOR_URI = '/wp-404-caching/404-template-generator/?generate=1&uri=1';

/**
* Get cache time.
*
* @return int
*/
public static function get_cache_time(): int {
return apply_filters( 'wp_404_caching_cache_time', self::DEFAULT_CACHE_TIME );
}

/**
* Get stale cache time.
*
* @return int
*/
public static function get_stale_cache_time(): int {
return apply_filters( 'wp_404_caching_stale_cache_time', self::DEFAULT_STALE_CACHE_TIME );
}

/**
* Boot the feature.
*/
Expand Down Expand Up @@ -254,8 +286,8 @@ public static function get_stale_cache(): mixed {
* @param string $buffer The Output Buffer.
*/
public static function set_cache( string $buffer ): void {
wp_cache_set( self::CACHE_KEY, $buffer, self::CACHE_GROUP, self::CACHE_TIME ); // phpcs:ignore WordPressVIPMinimum.Performance.LowExpiryCacheTime.CacheTimeUndetermined
wp_cache_set( self::STALE_CACHE_KEY, $buffer, self::CACHE_GROUP, self::STALE_CACHE_TIME ); // phpcs:ignore WordPressVIPMinimum.Performance.LowExpiryCacheTime.CacheTimeUndetermined
wp_cache_set( self::CACHE_KEY, $buffer, self::CACHE_GROUP, self::get_cache_time() ); // phpcs:ignore WordPressVIPMinimum.Performance.LowExpiryCacheTime.CacheTimeUndetermined
wp_cache_set( self::STALE_CACHE_KEY, $buffer, self::CACHE_GROUP, self::get_stale_cache_time() ); // phpcs:ignore WordPressVIPMinimum.Performance.LowExpiryCacheTime.CacheTimeUndetermined
}

/**
Expand Down

0 comments on commit bd889f2

Please sign in to comment.