conditional lscache folders?

mkaaaay

Well-Known Member
#1
Is it possible to have one set of cache files for the public, but then a second set of cache files for anyone say, with a certain cookie in their browser?

Basically, we hide product data if not logged in. We're happy to cache the logged in pages in their entirely provided we can verify that they are a logged in customer.

I tried setting a private cache but the load time was horrendous - worse than no cache at all.

Am I missing something?

Thank you v much.
 

serpent_driver

Well-Known Member
#2

mkaaaay

Well-Known Member
#3
Thanks a lot. I read it, but it's quite confusing.

So, if we use the vary directive would it be something like this?


<IfModule LiteSpeed>
RewriteRule .* - [E=Cache-Control:public, max-age=3600]
RewriteRule .* - [E=Cache-Vary:is_logged_in_cookie]
</IfModule>
 

serpent_driver

Well-Known Member
#4
Yes, it is almost complete, but you still need the cookie in your definition.

Code:
<IfModule LiteSpeed>
CacheLookup public on
RewriteRule .* - [E=cache-control:max-age=3600] 

RewriteCond %{HTTP_COOKIE} Cookie_Name_1 [NC]
RewriteRule .* - [E=Cache-Control:vary=is_logged_in_cookie]

RewriteCond %{HTTP_COOKIE} Cookie_Name_2 [NC]
RewriteRule .* - [E=Cache-Control:vary=is_logged_in_cookie_2]

....

</IfModule>
 

mkaaaay

Well-Known Member
#7
Yeah, I know - I've done a ton of reading, but tbh, the documentation kind of lacks a bit. It talks about different variables etc, but what's really lacking is seeing those variables in actual working code blocks. There are some of these, and they're super helpful but even then, some of these just don't work at all, even when copy/pasted.

It's all a bit of a dark art, until you see a working version of what it is you're trying to do, and then it makes sense.
 

mkaaaay

Well-Known Member
#8
I tried the following, but it doesn't work. The logged in user is still seeing the public cache of all non logged in users.


<IfModule LiteSpeed>
RewriteEngine On
RewriteCond %{REQUEST_URI} !login|admin|checkout
CacheLookup public on
RewriteRule .* - [E=cache-control:max-age=3600]

RewriteCond %{HTTP_COOKIE} logged_in_cookie [NC]
RewriteRule .* - [E=Cache-Control:vary=logged_in]

</IfModule>
 

mkaaaay

Well-Known Member
#9
even when done as this version, it still doesn't work.


<IfModule LiteSpeed>
CacheLookup public on
RewriteRule .* - [E=cache-control:max-age=3600]

RewriteCond %{HTTP_COOKIE} logged_in_cookie [NC]
RewriteRule .* - [E=Cache-Control:vary=logged_in]

</IfModule>
 

mkaaaay

Well-Known Member
#12
tbh, sending headers in php is much better, we have far more control over what pages to cache. Cookies create issues IMO.

So, what we need to happen is this:

people come to the site, and we send header as follows,
header('X-LiteSpeed-Cache-Control: public, max-age=3600, esi=on');

... they see public cache, all good.

Then, they log in, and as this site hides prices by default, we now want to show them the same pages, but with the prices AND, we want this price enabled version of the pages to be cached publicly, for anyone who is logged in

so now we send this:
header('X-LiteSpeed-Cache-Control: public, max-age=3600, esi=on');
header('X-LiteSpeed-Vary: vary=logged_in');

but the vary doesn't work

So, as you can see, we want to cache the pages twice, once with prices and ocne without, and how people based on if they're logged in or not (which we can easily detect in php)
 

serpent_driver

Well-Known Member
#14
Custom? AARrrggghhhhhhhhhhhhhhhhh :(

Custom doesn't mean that it doesn't work. It means it is impossible to teach you what to do on this way. What you need is more than 2 lines .htaccess code. So, forget it.... sorry
 

mkaaaay

Well-Known Member
#15
Why does custom mean this? Custom is not bad, our framework is 15 years old, it rocks.

The required concept is simple, and it shouldn't matter what framework is being used.

Simply: show one public cache if logged out, else show another public cache.

I don't understand why this is so difficult.
 

serpent_driver

Well-Known Member
#17
Custom isn't bad, ofcourse.

But you have some misunderstanding what it means if a URL is cached and you underestimate what is needed to get a full page cache like LScache work in an online shop. That is the big problem.
 

mkaaaay

Well-Known Member
#18
Not at all. I totally understand what it means for a page to be cached, and we have various cache busting techniques used already in the system (for cart contents, recently viewed prods, wishlist etc...). I totally get it, which is why I'm here.

The point here is, why is it not simply possible to serve two sep cache sets based on a user's status.

Full page caching is working fine for a site where the product prices and add to cart functionality are always displayed - we have that nailed.

It's just where add to cart is hidden behind a login that's the issue. yes, of course we could use ajax, but loading 100 ajax calls on a page is a horrible idea.

<esi inline> is the obvious solution, but no one seems to want to share this secret knowledge.

It's all pretty frustrating I have to say.
 

serpent_driver

Well-Known Member
#19
Simple situation to understand that is a little bit more complicated as you think. You wrote, if a user comes to your shop the first time you will set a header. You can do that, but if a URL is cached you cannot set anything with PHP, because the requested URL is pure HTML code. This is the same if you store a HTML page with your browser on your local PC. The cached page on your server is the same. So how will you set a header without PHP?

I understand why it seems to be frustrating for you, but what you want needs developer knowledge. There is no Copy & Paste solution for a custom shopping application.
 

mkaaaay

Well-Known Member
#20
Yes I do understand that, so then, we're back to cookies. The htaccess code you suggested just doesn't work.

We created cookies for testing and there was no change in the cached output.
 
Top