entry( $key ); return $entry ? $entry['count'] : 0; } public function incr( string $key, int $ttl ): int { $entry = $this->entry( $key ) ?? [ 'count' => 0, 'expires' => time() + $ttl, ]; ++$entry['count']; set_transient( self::name( $key ), $entry, max( 1, $entry['expires'] - time() ) ); return $entry['count']; } private function entry( string $key ): ?array { $entry = get_transient( self::name( $key ) ); if ( ! is_array( $entry ) || ! isset( $entry['count'], $entry['expires'] ) || $entry['expires'] <= time() ) { return null; } return $entry; } private static function name( string $key ): string { return 'advently_rl_' . md5( $key ); } }