Yoast\WP\SEO\Schema_Aggregator\Infrastructure

Config::get_expiration │ public │ Yoast 1.0

Get expiration time based on data size.

Метод класса: Config{}

Хуки из метода

Возвращает

int. Expiration in seconds.

Использование

$Config = new Config();
$Config->get_expiration( $data ): int;
$data(array) (обязательный)
Data to cache.

Код Config::get_expiration() Yoast 28.7

public function get_expiration( array $data ): int {
	$cache_ttl = self::DEFAULT_CACHE_TTL;
	try {
		$serialized = \serialize( $data ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize -- Needed for size calculation.

		$size = \strlen( $serialized );

		// Large payloads: cache longer.
		if ( $size > 1_048_576 ) {
			$cache_ttl = ( 6 * \HOUR_IN_SECONDS );
		}

		// Small payloads: cache shorter.
		if ( $size < 102_400 ) {
			$cache_ttl = ( 30 * \MINUTE_IN_SECONDS );
		}

		$cache_ttl = \apply_filters( 'wpseo_schema_aggregator_cache_ttl', $cache_ttl );

		if ( ! \is_int( $cache_ttl ) || $cache_ttl <= 0 ) {
			return self::DEFAULT_CACHE_TTL;
		}

		return $cache_ttl;

	} catch ( Exception $e ) {
		return self::DEFAULT_CACHE_TTL;
	}
}