Improve cache handling with on-demand cache warm-up and increase cURL timeout
- Implement on-demand warming of manual and automatic flags cache in `invoice_period_flag_service` to handle cache misses effectively. - Extend cURL timeout in `economic_endpoint_t` for improved reliability in network requests.
This commit is contained in:
@@ -384,11 +384,20 @@ class invoice_period_flag_service
|
||||
try {
|
||||
$flags = (new redis())->get_invoice_period_manual_flags();
|
||||
} catch (Throwable) {
|
||||
return [];
|
||||
$flags = null;
|
||||
}
|
||||
|
||||
if (!is_array($flags)) {
|
||||
return [];
|
||||
// Cache miss — warm on demand and re-fetch
|
||||
$this->warmManualFlagsCache();
|
||||
try {
|
||||
$flags = (new redis())->get_invoice_period_manual_flags();
|
||||
} catch (Throwable) {
|
||||
return [];
|
||||
}
|
||||
if (!is_array($flags)) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(array_filter($flags, static function ($flag): bool {
|
||||
@@ -516,11 +525,20 @@ class invoice_period_flag_service
|
||||
try {
|
||||
$flags = (new redis())->get_invoice_period_automatic_flags($dateFrom, $dateTo);
|
||||
} catch (Throwable) {
|
||||
return [];
|
||||
$flags = null;
|
||||
}
|
||||
|
||||
if (!is_array($flags)) {
|
||||
return [];
|
||||
// Cache miss — warm on demand and re-fetch
|
||||
$this->warmAutomaticFlagsForPeriod($dateFrom, $dateTo);
|
||||
try {
|
||||
$flags = (new redis())->get_invoice_period_automatic_flags($dateFrom, $dateTo);
|
||||
} catch (Throwable) {
|
||||
return [];
|
||||
}
|
||||
if (!is_array($flags)) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
if ($onlyCustomerNumbers === null) {
|
||||
@@ -592,11 +610,16 @@ class invoice_period_flag_service
|
||||
try {
|
||||
$rows = (new redis())->get_invoice_period_order_item_rows($dateFrom, $dateTo);
|
||||
} catch (Throwable) {
|
||||
return [];
|
||||
$rows = null;
|
||||
}
|
||||
|
||||
if (!is_array($rows)) {
|
||||
return [];
|
||||
// Cache miss — fetch from DB and cache for next request
|
||||
$rows = $this->fetchOrderItemRowsFromDb($dateFrom, $dateTo);
|
||||
try {
|
||||
(new redis())->cache_invoice_period_order_item_rows($dateFrom, $dateTo, $rows);
|
||||
} catch (Throwable) {
|
||||
}
|
||||
}
|
||||
|
||||
$this->seedOrderItemsPreviewCacheFromRows($rows);
|
||||
|
||||
@@ -148,7 +148,7 @@ trait economic_endpoint_t
|
||||
//CURLOPT_ENCODING => '',
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_CONNECTTIMEOUT => 3,
|
||||
CURLOPT_TIMEOUT => 10,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2TLS,
|
||||
CURLOPT_CUSTOMREQUEST => $method,
|
||||
|
||||
Reference in New Issue
Block a user