Skip to content

Commit 8011af2

Browse files
committed
Refactor.
1 parent a9a5fc4 commit 8011af2

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

src/Cache.php

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -250,38 +250,35 @@ public function __destruct()
250250
$this->WorkingData->close();
251251
return;
252252
}
253-
if ($this->Using === 'PDO') {
254-
$this->clearExpiredPDO();
253+
if (!\is_array($this->WorkingData)) {
255254
return;
256255
}
257-
if (\is_array($this->WorkingData)) {
258-
if ($this->clearExpired($this->WorkingData)) {
259-
$this->Modified = true;
260-
}
261-
if ($this->FFDefault && $this->Modified && $this->Using === 'FF') {
262-
$Handle = false;
263-
$Start = \time();
264-
while (true) {
265-
$Handle = \fopen($this->FFDefault, 'wb');
266-
if ($Handle !== false || (\time() - $Start) > self::FLOCK_TIMEOUT) {
267-
break;
268-
}
269-
}
270-
if ($Handle === false) {
271-
return;
272-
}
273-
$Locked = false;
274-
while (true) {
275-
if ($Locked = \flock($Handle, \LOCK_EX | \LOCK_NB) || (\time() - $Start) > self::FLOCK_TIMEOUT) {
276-
break;
277-
}
256+
if ($this->clearExpired($this->WorkingData)) {
257+
$this->Modified = true;
258+
}
259+
if ($this->FFDefault && $this->Modified && $this->Using === 'FF') {
260+
$Handle = false;
261+
$Start = \time();
262+
while (true) {
263+
$Handle = \fopen($this->FFDefault, 'wb');
264+
if ($Handle !== false || (\time() - $Start) > self::FLOCK_TIMEOUT) {
265+
break;
278266
}
279-
if ($Locked) {
280-
\fwrite($Handle, \serialize($this->WorkingData));
281-
\flock($Handle, LOCK_UN);
267+
}
268+
if ($Handle === false) {
269+
return;
270+
}
271+
$Locked = false;
272+
while (true) {
273+
if ($Locked = \flock($Handle, \LOCK_EX | \LOCK_NB) || (\time() - $Start) > self::FLOCK_TIMEOUT) {
274+
break;
282275
}
283-
\fclose($Handle);
284276
}
277+
if ($Locked) {
278+
\fwrite($Handle, \serialize($this->WorkingData));
279+
\flock($Handle, \LOCK_UN);
280+
}
281+
\fclose($Handle);
285282
}
286283
}
287284

src/DelayedIO.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Delayed file IO class (last modified: 2026.03.17).
3+
* Delayed file IO class (last modified: 2026.03.20).
44
*
55
* This file is a part of the "common classes package", utilised by a number of
66
* packages and projects, including CIDRAM and phpMussel.
@@ -129,7 +129,7 @@ public function readFile(string $File = '', int $Lock = 0): string
129129
$Time = \time();
130130
$Unlocked = false;
131131
while (!$Unlocked) {
132-
$Unlocked = \flock($Handle, LOCK_UN);
132+
$Unlocked = \flock($Handle, \LOCK_UN);
133133
if (!$Unlocked && (\time() - $Time) >= self::LOCK_TIMEOUT) {
134134
break;
135135
}

0 commit comments

Comments
 (0)