Lscache is caching blank results

#1
Hi,

I am on a v1.7.7.3 prestashop withd php 7.2, I am using lscache for prestashop v1.4

Globally the cache is doing fine, but sometimes it put in cache products pages that have a blank result (because of errors), the response then is a blank page in cache, only flushing the cache for that specific page helps.

My problem is random then, if the page is not cached and have an error at that moment then it gives a blank page to the visitor and caches that result, so every visitor after the first one also have the issue versus only one person without the cache.

I know that idealy I should fix the issue causing the blank page but I would like to know if I can configure something with lscache to never cache blank results.

How to do that ?

Thanks in advance :)
 

serpent_driver

Well-Known Member
#2
There is nothing you can configure.

What you describe is a known problem, but it is not limited to the cache plugin for PrestaShop, but can be found in every cache plugin for other applications as well. The problem is a political problem. LiteSpeed takes the position that error pages should or must be cached as well. Personally, I don't share this view because there's no meaningful use for caching error pages. You can therefore only write a feature request and hope that LiteSpeed will change their minds.

Nevertheless, you should solve the cause of your errors.
 
#3
Thank you very much for your anwser, is there another way to detect that ? like checking the cache for error and flushing them, with a script ??
 

serpent_driver

Well-Known Member
#6
This is possible, but only if a page isn't cached yet. If a page with errors is already cached, there is no way to check anything, because a cached page is only plain text and there is no more PHP interpretor. You must find a way to add this code in PrestaShop, but it must be last header that is set. This code works, but without guarantee if it works with status code 500. If it works then error page isn't cached.

PHP:
$get_response_code = http_response_code();
if ($get_response_code == 500) {
    header('x-litespeed-cache-control:no-cache');
}
 
#7
For this to work I guess that the error must be catched because if the execution stops then I will be unable to get the response code with php :/ not sure i'm right here.

My initial thought was not to catch the error while it happen, but somehow use the api of lscache to check empty pages and flush them. Not sure it is possible though.
 

serpent_driver

Well-Known Member
#8
My initial thought was not to catch the error while it happen, but somehow use the api of lscache to check empty pages and flush them. Not sure it is possible though.
No, this isn't possible. LScache is a web server based http cache and not a script language like PHP. The cache plugin itself doesn't cache anything. It's just a control panel.

For this to work I guess that the error must be catched because if the execution stops then I will be unable to get the response code with php :/ not sure i'm right here.
No, you are wrong. For the cache function it doesn't matter if a page has any errors. The cache without control is like a sports car, but without brakes and steering wheel. It caches everything and that's why you need a control panel or a plugin that controls the cache. To make it possible what you want you need PHP to check for the status code and if it is status code 500 you can set cache-control header.
 
Top