From 74d3272c373f7f0c55007f4fd3603155cef2cec4 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Thu, 20 Jan 2022 16:31:46 -0600 Subject: [PATCH] Better error handling if a user tries to get a book while the library cache is being rebuilt --- lib/Library.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/Library.php b/lib/Library.php index 8c393cd3..3eceb542 100644 --- a/lib/Library.php +++ b/lib/Library.php @@ -108,7 +108,21 @@ class Library{ } catch(Safe\Exceptions\ApcuException $ex){ Library::RebuildCache(); - $ebooks = apcu_fetch('ebooks'); + try{ + $ebooks = apcu_fetch('ebooks'); + } + catch(Safe\Exceptions\ApcuException $ex){ + // We can get here if the cache is currently rebuilding from a different process. + // Nothing we can do but wait, so wait 20 seconds before retrying + sleep(20); + + try{ + $ebooks = apcu_fetch('ebooks'); + } + catch(Safe\Exceptions\ApcuException $ex){ + // Cache STILL rebuilding... give up silently for now + } + } } return $ebooks;