Purge cache problem

#1
Hello, I'm using Laravel package(lscache-laravel), when the user login and after that logout and login again the cache is not cleared and the webserver is responding with a cached version of the page(header x-litespeed-cache: hit). The whole website is using vuejs as frontend for auth is used the default one

After user has logged in and logged out, I'm purging the cache.
Settings of lscache.php config are:
esi = false
default_ttl= 300
default_cacheability = public
guest_only=true

I put ->header('X-LiteSpeed-Purge', 'stale,*'); on response on login/logout but the cache again is not purged after the 2-nd login.


I'm using OpenLiteSpeed.
 
#3
The syntax is fine.
https://laravel.com/docs/7.x/responses#attaching-headers-to-responses

In the header you must set key and value.
Also when you return response()->json() i have to set header in the json like that


PHP:
 return response()->json('', 200, [ 'X-LiteSpeed-Purge' => 'stale,*']);
I also try to change the part with guest and logged in user in the lscache middleware.

PHP:
        if ($guest_only === true && auth()->check() === true) {

            if ($response->headers->has('X-LiteSpeed-Cache')){
                $response->headers->set('X-LiteSpeed-Purge',  'stale,*');
            }

            $response->headers->set('X-LiteSpeed-Cache-Control',  'no-cache');
            return $response;
        }
 

serpent_driver

Well-Known Member
#4
Sorry, I couldn't know complete context of code and the method how to set header in Laravel.

If cache will not be cached maybe you set header to late. You must set the header before POST request is finished.

Example:
PHP:
if (isset($_POST['action']) && ($_POST['action'] == 'whatever')) {
       header('X-LiteSpeed-Purge:stale,*'); 
}
That is how I solve it in my applications when users login.
 
#7
Okay, lets go again. :D
Example:
User James is logging on the website, after 5 seconds he logout by mistake. He saw his mistake and login again but now the page is served from the OLS, not by the php.

Login controller:
Login response
PHP:
        protected function sendLoginResponse (Request $request)
        {
            $request->session()->regenerate();

            $this->clearLoginAttempts($request);

            if ($response = $this->authenticated($request, $this->guard()->user())) {
                return $response;
            }

            if (!$request->isJson()){
                return  redirect()->intended($this->redirectPath());
            }

            return response()->json('', 200, [ 'X-LiteSpeed-Purge' => 'stale,*']);
        }
logout response
PHP:
        public function logout (Request $request)
        {
            $this->guard()->logout();

            $request->session()->invalidate();

            $request->session()->regenerateToken();

            if ($response = $this->loggedOut($request)) {
                return $response;
            }


            return response()->json('', 200, [ 'X-LiteSpeed-Purge' => 'stale,*']);
        }
Even if I put
LSCache:: purgeAll(); it doesn't help at all.
 
#9
Is not working with LSCache::purgeAll(); i have tried this in the beginning. Like Openlitespeed doesn't recognize the header X-LiteSpeed-Purge

Edit:
OLS version is 1.7.4
 
#14
Yes authorization is on a subdomain with no-cache and auth tag.
So after this test with the blank file and header, I tried to put
PHP:
header('X-LiteSpeed-Purge:stale,*');
in the index.php file and it works. Seems like when the header is put in the controller or in the routers file it's ignored.

From the blank file, I tried to clear the cache with tag=website but didn't clear it.

Frontend(Vuejs) is making requests to the backend(Laravel, the API is on subdomain). But why after only the 2-nd login OLS is showing a cached copy.
 

serpent_driver

Well-Known Member
#15
I tried to clear the cache with tag=website but didn't clear it.
1.) To purge cache by tag page must be cached with tag first. If cache is purged you must see tag name in response header.
2.)
return response()->json('', 200, [ 'X-LiteSpeed-Purge' => 'stale,*']);
Replace this header with a test header like:

PHP:
return response()->json('', 200, [ 'Testheader' => 'test']);
and check response header if you request login page. If test header exist purge header will also be set, but the way you set the header is wrong.
 

serpent_driver

Well-Known Member
#16
For your information: OLS has some restrictions in comparison to LSWS Enterprise. A restriction can be a delay when cache will be purged. This seems to be undocumented. Another user of OLS reported this and got this information from his hosting provider. Maybe this could cause your issue
 
Top