Better error handling if a user tries to get a book while the library cache is being rebuilt

This commit is contained in:
Alex Cabal 2022-01-20 16:31:46 -06:00
parent 4acd88d08a
commit 74d3272c37

View file

@ -108,8 +108,22 @@ class Library{
} }
catch(Safe\Exceptions\ApcuException $ex){ catch(Safe\Exceptions\ApcuException $ex){
Library::RebuildCache(); Library::RebuildCache();
try{
$ebooks = apcu_fetch('ebooks'); $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; return $ebooks;
} }