2024-04-10 22:23:34 +00:00
|
|
|
<?php
|
|
|
|
// MemcachedProviderInfo.php
|
|
|
|
// Created: 2024-04-10
|
2024-08-03 20:27:50 +00:00
|
|
|
// Updated: 2024-08-03
|
2024-04-10 22:23:34 +00:00
|
|
|
|
|
|
|
namespace Index\Cache\Memcached;
|
|
|
|
|
|
|
|
use InvalidArgumentException;
|
|
|
|
use Index\Cache\ICacheProviderInfo;
|
2024-08-03 20:27:50 +00:00
|
|
|
use Index\Net\EndPoint;
|
2024-04-10 22:23:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents Memcached provider info.
|
|
|
|
*/
|
|
|
|
class MemcachedProviderInfo implements ICacheProviderInfo {
|
2024-08-03 20:27:50 +00:00
|
|
|
/**
|
|
|
|
* @param array<int, array{EndPoint, int}> $endPoints Memcached end points.
|
|
|
|
* @param string $prefixKey Prefix to apply to keys.
|
|
|
|
* @param string $persistName Persistent connection name.
|
|
|
|
* @param bool $useBinaryProto Use the binary protocol.
|
|
|
|
* @param bool $enableCompression Use compression.
|
|
|
|
* @param bool $tcpNoDelay Disable Nagle's algorithm.
|
|
|
|
*/
|
2024-04-10 22:23:34 +00:00
|
|
|
public function __construct(
|
|
|
|
private array $endPoints,
|
|
|
|
private string $prefixKey,
|
|
|
|
private string $persistName,
|
|
|
|
private bool $useBinaryProto,
|
|
|
|
private bool $enableCompression,
|
|
|
|
private bool $tcpNoDelay,
|
|
|
|
) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets server endpoints.
|
|
|
|
*
|
2024-08-03 20:27:50 +00:00
|
|
|
* @return array<int, array{EndPoint, int}>
|
2024-04-10 22:23:34 +00:00
|
|
|
*/
|
|
|
|
public function getEndPoints(): array {
|
|
|
|
return $this->endPoints;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A prefix that gets applied to every key.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getPrefixKey(): string {
|
|
|
|
return $this->prefixKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the connection should be persistent.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isPersistent(): bool {
|
|
|
|
return $this->persistName !== '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of persistent connection, will return null if disabled.
|
|
|
|
*
|
|
|
|
* @return ?string
|
|
|
|
*/
|
|
|
|
public function getPersistentName(): ?string {
|
|
|
|
return $this->persistName === '' ? null : $this->persistName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the binary protocol should be used rather than ASCII.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function shouldUseBinaryProtocol(): bool {
|
|
|
|
return $this->useBinaryProto;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether compression should be applied.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function shouldEnableCompression(): bool {
|
|
|
|
return $this->enableCompression;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether nagle's algorithm should be disabled on the connection.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function shouldTcpNoDelay(): bool {
|
|
|
|
return $this->tcpNoDelay;
|
|
|
|
}
|
|
|
|
}
|