WP_AI_Client_Cache::ttl_to_seconds
Converts a PSR-16 TTL value to seconds for WordPress cache functions.
Method of the class: WP_AI_Client_Cache{}
No Hooks.
Returns
Int. The TTL in seconds, or 0 for no expiration.
Usage
// private - for code of main (parent) class only $result = $this->ttl_to_seconds( $ttl ): int;
- $ttl(null|int|DateInterval) (required)
- The TTL value.
Changelog
| Since 7.0.0 | Introduced. |
WP_AI_Client_Cache::ttl_to_seconds() WP AI Client Cache::ttl to seconds code WP 7.0
private function ttl_to_seconds( $ttl ): int {
if ( null === $ttl ) {
return 0;
}
if ( $ttl instanceof DateInterval ) {
$now = new DateTime();
$end = ( clone $now )->add( $ttl );
return $end->getTimestamp() - $now->getTimestamp();
}
return max( 0, (int) $ttl );
}