diff --git a/CHANGELOG.md b/CHANGELOG.md index 78302ea..f012e23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 2.0.2 under development -- no changes in this release. +- Chg #50: Do not throw exception on file delete when file not found (fix for high concurrency load) (@sartor) ## 2.0.1 September 18, 2022 diff --git a/src/FileCache.php b/src/FileCache.php index 88a0070..15fc498 100644 --- a/src/FileCache.php +++ b/src/FileCache.php @@ -168,7 +168,17 @@ public function delete(string $key): bool return true; } - return @unlink($file); + $result = @unlink($file); + // Check if error was because of file was already deleted by another process on high load + if ($result === false) { + $lastError = error_get_last(); + if (str_ends_with($lastError['message'] ?? '', 'No such file or directory')) { + error_clear_last(); + return true; + } + } + + return $result; } public function clear(): bool