|
|

01-07-2011, 07:08 PM
|
|
LiteSpeed Staff
|
|
Join Date: Sep 2009
Posts: 2,216
|
|
yes, lsws can. for example,
Code:
RewriteCond %{HTTP_COOKIE} username=guest
RewriteRule /index.php - [E=Cache-Control:max-age=600]
if uasename=guest exists in cookies, lsws cache /index.php page for 600 seconds(10 minutes).
for subsequent requests:
if there is uasename=guest cookie in request header, lsws return the cached index.php; if not exist, lsws will pass the request to lsphp5, and return the user output of lsphp5.
|

01-11-2011, 05:53 AM
|
|
Member
|
|
Join Date: Apr 2010
Posts: 47
|
|
|
I stand corrected, that's nice to know. Makes it a lot more flexible than QUERY only.
SESSION would still be ultimate but at least now we can simply drop a cookie parameter that tells us whether or not LSWS should show a cached page or a live one.
|

01-11-2011, 08:39 AM
|
|
Member
|
|
Join Date: Apr 2010
Posts: 47
|
|
Do these rules only work after we configure Server > Cache or VHost > [VHOST] > Cache in the admin GUI?
And we simply put them in htaccess file just like other Mod_Rewrite rules, right?
And how can we verify whether it's working, does it output certain headers we can look for that indicate this comes form LSWS's cache?
Lastly, can we do something like this, to only trigger if there isn't a Cookie with any value?
Code:
RewriteCond !%{HTTP_COOKIE} username=*
RewriteRule /index.php - [E=Cache-Control:max-age=600]
I really do suck at mod_rewrite... Thanks for your help.
Last edited by J.T.; 01-11-2011 at 08:46 AM..
|

01-11-2011, 04:51 PM
|
|
LiteSpeed Staff
|
|
Join Date: Sep 2009
Posts: 2,216
|
|
rtight, it works in .htaccess, just like other rewrite rules.
currently, no special response header to indicate it's from cache.
however, it's easy to verify if it's from cache or not. for example,
PHP Code:
<?php
header('CurrentTime: '.gmdate('D, d M Y H:i:s', time()).' GMT',true);
echo "time()=" . time() . "<br>";
echo "date()=" . date(DATE_RFC822) ."<br>";
?>
the output of this page changes for every visit if no cache.
with cache enabled, the page has no change until cache expire 10 minutes later.
the rewrite rule should be:
Code:
RewriteCond %{HTTP_COOKIE} !username=
RewriteRule /index.php - [E=Cache-Control:max-age=600]
|

01-11-2011, 11:25 PM
|
|
Senior Member
|
|
Join Date: Dec 2004
Location: Brisbane, Australia
Posts: 142
|
|
Quote:
Originally Posted by NiteWave
the rewrite rule should be:
Code:
RewriteCond %{HTTP_COOKIE} !username=
RewriteRule /index.php - [E=Cache-Control:max-age=600]
|
Adding my questions here too
1. how would you do this at server level - for all virtualhosts on a WHM/Cpanel apache virtualhost configured server running litespeed ? for just specific php pages and/or for all php served pages on all virtualhosts ?
2. would that rewrite url not for index.php not cache index.php?page=variable ? or with friendly urls index.php/variable ?
3. In above example if cookie has guest in it cache index.php, would you need to enable these 2 options for it to work ? Cache Request with Cookie and Cache Response with Cookie ?
4. Is it still true this caching doesn't work with vBulletin as per statement at http://www.litespeedtech.com/support...51&postcount=6 or that is old outdated info ?
I read somewhere i'd need to compile apache with mod_cache, in pre main include add something like
CacheRoot /home/lswscache/
CacheEnable disk /
but how do you only cache guest/visitors without cookie then ?
thanks
Last edited by eva2000; 01-12-2011 at 01:32 AM..
|

01-12-2011, 01:36 AM
|
|
LiteSpeed Staff
|
|
Join Date: Sep 2009
Posts: 2,216
|
|
1.
it's possible to cache dynamic page(for example php) at server and each vhost level, without using rewriterule. This thread is talking about cache with rewriterule, which is litespeed specific feature and very useful in practice.
2. cache the original URI -- i.e., the URL in browser's address.
if "Cache Request with Query String"=Yes, then will cache page "index.php?page=variable"; otherwise won't cache it.
the rewriterule
Code:
RewriteRule /index.php - [E=Cache-Control:max-age=600]
won't cache "index.php/variable", since it's a different URI.
however, if the rewrite rule is
Code:
RewriteRule /index.php(/.*)? - [E=Cache-Control:max-age=600]
then both /index.php and /index.php/variable will be cached, since both matches the cache condition.
3.right, need set "Cache Request with Cookie"=Yes
4."how do you only cache guest/visitors without cookie"
Code:
RewriteCond %{HTTP_COOKIE} ^$
RewriteRule /index.php - [E=Cache-Control:max-age=600]
|

01-12-2011, 03:42 AM
|
|
Senior Member
|
|
Join Date: Dec 2004
Location: Brisbane, Australia
Posts: 142
|
|
Quote:
Originally Posted by NiteWave
1.
4."how do you only cache guest/visitors without cookie"
Code:
RewriteCond %{HTTP_COOKIE} ^$
RewriteRule /index.php - [E=Cache-Control:max-age=600]
|
thanks mate good info - wish documentation would explain and outline this stuff 
So for vbulletin usage, if i compile apache with mod_cache support, add into pre main include
CacheRoot /home/lswscache/
CacheEnable disk /
litespeed would cache all files in all virtualhosts without cookies (the default settings) ? is that the same (for index.php) as specifying in htaccess as below
Code:
RewriteCond %{HTTP_COOKIE} ^$
RewriteRule /index.php - [E=Cache-Control:max-age=600]
?
So index.php without cookies, would be cached for guest/visitors fwithout this rewrite anyway ? Same with rest of vB php files for guest/visitors even with this rewrite rule would be cached, as default is to cache without cookies ?
|

01-12-2011, 08:54 AM
|
|
LiteSpeed Staff
|
|
Join Date: Sep 2009
Posts: 2,216
|
|
|
for vBulletin, unfortunately, every guest visitor will be set cookies, so it'll not working as you expected. caching vBulletion for guest users is a bit more complicated, but it's possible under litespeed. In fact, we've tried to cache this vBulletin (litespeed suport forum) for guest visitors for a few weeks and looks working well. We can open an new thread to discuss our implementation to cache vBulletin under litespeed.
|

01-12-2011, 09:12 AM
|
|
Member
|
|
Join Date: Apr 2010
Posts: 47
|
|
Thanks for the detailed examples, that's really helpful. Last questions, I think!
1. If we put those rules in htaccess, do we also have to turn caching on in the admin?
2. In the admin > Server > Cache I have Storage Path /home/lswscache - which permissions do you recommend? The VH I'm testing caching with seems to run as lsadm
I tried yesterday, before reading your post, like this:
Code:
RewriteRule /index.php - [E=Cache-Control:max-age=120]
So no conditions, just all-out caching. It didn't seem to work and I think it's to do with URL rewriting.
3. Would a rule for www.domain.org/index.php also cover www.domain.org/ ? Probably not.
4. And if I have a URL like www.domain.org/product1.html which is in fact a rewritten URL for www.domain.org/products/1 do I need to make the caching rewrite URL to match the original, or the rewritten URL?
5. Last question, if we have an index.php page which outputs "Hello NiteWave, welcome to our site" because it recognises it was you from last time, if it then caches that page, with that text, will it show exactly that to other users,with your name? I guess it will, and that's why we need to look for cookie values, for example.
After piecing together the bits of documentation and with your help here, I finally get to grips with this, thank you very much. I also happen to have another vBulletin site on a VPS with Litespeed, but it seems the license for that server doesn't include these caching options.
Last edited by J.T.; 01-12-2011 at 09:14 AM..
|

01-12-2011, 09:58 AM
|
|
LiteSpeed Staff
|
|
Join Date: Sep 2009
Posts: 2,216
|
|
|
1. yes. That's where to define your cache policy. Here's an example for litespeed native configured vhost:
Cache Request with Query String:Yes
Cache Request with Cookie:Yes
Cache Response with Cookie:Yes
Ignore Request Cache-Control:Yes
Ignore Response Cache-Control:Yes
2. the user running litespeed process will create and fetch cache from cache directory -- for example "nobody". set the cache folder owner to nobody, and permission to 700, should be ok.
3.tested, the answer: "/" is covered. the condition is "index.php" is the vhost's index page. this also true: if you cache "^/$" only, and index.php is the index page, access / will result access to /index.php, then cache "/" covers /index.php
4.the original URL. Note: lsws only cache dynamic page(php etc). if product1.html is a pure static html, it won't be cached.
5.yes, it will.
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 07:02 PM.
|
|