Skip to content

Commit

Permalink
Optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Dec 18, 2024
1 parent 3dbb235 commit cf97712
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions src/Connection/TcpConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,6 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
*/
protected static int $idRecorder = 1;

/**
* Cache.
*
* @var bool
*/
protected static bool $enableCache = true;

/**
* Socket
*
Expand Down Expand Up @@ -674,7 +667,7 @@ public function baseRead($socket, bool $checkEof = true): void
} else {
$this->bytesRead += strlen($buffer);
if ($this->recvBuffer === '') {
if (static::$enableCache && isset($requests[$buffer])) {
if (!isset($buffer[static::MAX_CACHE_STRING_LENGTH]) && isset($requests[$buffer])) {
++self::$statistics['total_request'];
$request = $requests[$buffer];
if ($request instanceof Request) {
Expand Down Expand Up @@ -752,7 +745,7 @@ public function baseRead($socket, bool $checkEof = true): void
try {
// Decode request buffer before Emitting onMessage callback.
$request = $this->protocol::decode($oneRequestBuffer, $this);
if (static::$enableCache && (!is_object($request) || $request instanceof Request) && $one && !isset($oneRequestBuffer[static::MAX_CACHE_STRING_LENGTH])) {
if ((!is_object($request) || $request instanceof Request) && $one && !isset($oneRequestBuffer[static::MAX_CACHE_STRING_LENGTH])) {
($this->onMessage)($this, $request);
if ($request instanceof Request) {
$request->destroy();
Expand Down Expand Up @@ -1088,16 +1081,6 @@ public function destroy(): void
}
}

/**
* Enable or disable Cache.
*
* @param bool $value
*/
public static function enableCache(bool $value = true): void
{
static::$enableCache = $value;
}

/**
* Init.
*
Expand Down

0 comments on commit cf97712

Please sign in to comment.