====== LSCache + IP Board ======
In order for LSCache and IP Board to work together, IP Board needs to be modified to send out
a ‘Cache-Control: Private’ response header to logged-in users. LSWS will take care of the rest.
===== Procedures =====
Here are the steps that will enable LSWS to work with IP Board:
==== Modify IP Board code ====
File admin/sources/classes/output/formats/html/htmlOutput.php needs to be modified to
send out a ‘**cache-control: private**’ response header to logged-in users. Essentially, the
response header is a flag that notifies LSWS what kind of cache to serve, which is the only
information LSWS needs to know in order to work with IP Board.
Below changes are for IPB v3.1.4 as an example:
# diff -Naur a/htmlOutput.php b/htmlOutput.php
—-- a/htmlOutput.php 2011-03-16 15:39:09.000000000 -0400
+++ b/htmlOutput.php 2011-06-27 00:39:38.000000000 -0400
@@ -73,6 +73,17 @@
public function printHeader()
{
//—————————————–
+ // Add "cache-control: private" header
+ // for logged in users
+ // this is for LiteSpeed cache requirement
+ //—————————————–
+ if ( $this->memberData['member_id'] )
+ {
+ header( "cache-control: private" );
+ }
+
+
+ //—————————————–
// Start GZIP compression
//—————————————–
@@ -1062,4 +1073,4 @@
return $texts[ array_rand($texts) ];
}
#
**Note:** To verify, check the response header when you log in. Server response header
"Cache-Control: private" should be seen:
HTTP/1.1 200 OK
Content-Encoding: gzip
Vary: Accept-Encoding
Transfer-Encoding: chunked
Date: Wed, 20 Jul 2011 16:59:30 GMT
Server: LiteSpeed
Connection: close
...
Cache-Control: private <==== this is the header
...
==== Set up Cache Policy ====
In LiteSpeed (v4.1.2 or later) Admin CP -> Configuration -> Server -> Cache
Storage Path: /dev/shm/diskcache
Max Object Size: 1024000
Cache Policy
Enable Cache: No
Cache Expire Time (seconds): Not Set
Cache Request with Query String: No
Cache Request with Cookie: Yes
Cache Response with Cookie: Yes
Ignore Request Cache-Control: Yes
Ignore Response Cache-Control: No
Enable Private Cache: Yes
Private Cache Expire Time (seconds): 60
Do-Not-Cache URL(s):
/index.php?app=forums&module=post§ion=post&do=edit_post
/index.php?app=forums&module=post§ion=post&do=reply_post
/index.php?app=forums&module=moderate§ion=moderate&do=postchoice
**Note:** Do-Not-Cache URL box holds all of the URL(s) that should **NOT** be cached.
==== Create Rewrite Rules for guest/public caching ====
Input the following rules into .htaccess in front of existing Rewrite rules.
RewriteEngine On
###########################################
# For LiteSpeed public cache (guest user)
###########################################
RewriteCond %{REQUEST_METHOD} ^HEAD|GET$
RewriteCond %{HTTP_COOKIE} !member_id= [OR]
RewriteCond %{HTTP_COOKIE} member_id=0
RewriteCond %{REQUEST_URI} !^/admin
RewriteCond %{REQUEST_URI} !(css|js|png|gif)$
RewriteRule .* - [E=Cache-Control:max-age=360]
**Note:**
- Above rules are for guest user (the cookie does not contain ‘member_id’ at all or contains ‘member_id=0’).
- Do NOT cache for admin user.
- Do NOT cache static objects.
- Cache for 6 minutes.
- For public cache, "X-LiteSpeed-Cache: hit" response header should be seen.
- For private cache, "X-LiteSpeed-Cache: private,hit" response header should be seen.
==== Create cronjob code to clean up stale cache ====
0 */2 * * * find /dev/shm/diskcache -type f -mmin 120 –delete
==== Add entries to /etc/rc.local ====
echo "mkdir /dev/shm/diskcache && chmod nobody.lsadm" >> /etc/rc.local
echo "/dev/shm/diskcache && chmod 770 /dev/shm/diskcache" >> /etc/rc.local
**Note:** this is to make sure cache directory gets created when server is booted up.