litespeedtech / lscache-laravel

LSCache for Laravel framework
GNU General Public License v3.0
51 stars 14 forks source link

Purging issues after last update on v1.1.0 #5

Closed darkperis closed 4 years ago

darkperis commented 4 years ago

LSCache::purge('*'); <--- WORKS

LSCache::purge('/'); <--- NOT purging homepage LSCache::purge('/this-is-a-post-slug'); <--- NOT purging specific slug

As a result I have to purge all every time a new post is added. Please advise.

lucasRolff commented 4 years ago

Are you using OpenLiteSpeed or LiteSpeed Web Server Enterprise?

darkperis commented 4 years ago

LiteSpeed Web Server Enterprise

lucasRolff commented 4 years ago

Deploying a Laravel appliaction (e.g. latest version of Laravel), and installing the lscache laravel package using composer and adding 3 routes:

Route::get('/', function () {
    return "Home";
})->middleware('lscache:max-age=3600;public');

Route::get('/purge', function() {
    LSCache::purge('/about');
    return "Purged";
});

Route::get('/about', function() {
    return "About";
})->middleware('lscache:max-age=3600;public');

Setting up two loops of curl using curl -sIXGET https://example.com/ and curl -sIXGET https://example.com/about

Both endpoints will list X-LiteSpeed-Cache: hit

Then calling the /purge URL, will purge the /about page, which will result in a X-LiteSpeed-Cache: miss header being returned for /about.

Upgrading from a 1.0.x version reveals the same behavior.

The only thing that really changed in version 1.1.0, is that we're using stale purge instead of a normal purge, the benefit being only 1 user will get a "miss" (and process the page), while everyone else hitting the page in the meantime will get the "hit" from the stale page.

Depending on how/when you're doing your purge, it may be that your request that you do that gets a hit, are indeed being served a stale cache, because the page is already being generated.

darkperis commented 4 years ago

This is not the case because even after 10 requests (after purging) on the same url (which should be purged), the contents remains old. New content is shown only after a purge ALL request.

lucasRolff commented 4 years ago

Try enable debug logging in litespeed web server then by using killall -USR2 litespeed.

Load the page that does the purge request, and check for [CACHE] and X-LiteSpeed-Purge, you should see whether it actually purges.

E.g. on the above code, it will give the following result:

[DEBUG] [14340] [10.10.10.10:60851#APVH_example.com:lsapi] [CACHE] PURGE public: stale,/about

To disable debug logging again, you can once again do killall -USR2 litespeed

darkperis commented 4 years ago

The problem was that I was trying to purge at the same time the homepage and the post slug.

LSCache::purge('/this-is-a-post-slug1'); LSCache::purge('/');

When I am purging one at a time, it works.

Thanks for your help!