Limit dynamic image Redis caching to default variant
This commit is contained in:
@@ -162,20 +162,27 @@ class departmentLanesRoute
|
||||
// Cache check
|
||||
$cacheKey = null;
|
||||
if (defined('redis')) {
|
||||
$cacheParams = [
|
||||
'dynamic_image_id' => $dynamic_image_id,
|
||||
'buttons' => $buttons,
|
||||
'current_step' => $current_step,
|
||||
'only_current_step' => (bool)$only_current_step,
|
||||
'vehicle_type' => $vehicle_type
|
||||
];
|
||||
$cacheKey = 'dynamic_image:' . md5(json_encode($cacheParams));
|
||||
$cachedImage = redis->get($cacheKey);
|
||||
if ($cachedImage) {
|
||||
header('Content-Type: image/png');
|
||||
header('Content-Length: ' . strlen($cachedImage));
|
||||
echo $cachedImage;
|
||||
exit;
|
||||
// Cache only the default image variant to avoid unbounded cache key growth
|
||||
// from request-controlled parameters (buttons/current_step/etc.).
|
||||
$isDefaultVariant = $buttons === null
|
||||
&& $current_step === 0
|
||||
&& !(bool)$only_current_step
|
||||
&& $vehicle_type === null;
|
||||
|
||||
if ($isDefaultVariant) {
|
||||
$cacheParams = [
|
||||
'department' => $department_id,
|
||||
'lane' => $lane_id,
|
||||
'dynamic_image_id' => $dynamic_image_id,
|
||||
];
|
||||
$cacheKey = 'dynamic_image:' . md5(json_encode($cacheParams));
|
||||
$cachedImage = redis->get($cacheKey);
|
||||
if ($cachedImage) {
|
||||
header('Content-Type: image/png');
|
||||
header('Content-Length: ' . strlen($cachedImage));
|
||||
echo $cachedImage;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,4 +349,4 @@ class departmentLanesRoute
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user