|
litespeed_wiki:litespeed:cache:joomla 2012/01/18 19:49 |
litespeed_wiki:litespeed:cache:joomla 2012/01/18 20:06 current |
| | LiteSpeed webserver (LSWS) cache bypasses php invocation and serves cached page directly from LSWS cache. Hence a much bigger performance improvement can be achieved. | | LiteSpeed webserver (LSWS) cache bypasses php invocation and serves cached page directly from LSWS cache. Hence a much bigger performance improvement can be achieved. |
| | | | |
| - | To work with Joomla (cached for guest visitor or logged-in user), LSWS cache relies on a cookie token to differentiate whether a user is logged in or not. However, Joomla assigns cookie to any user (guest and logged-in). cookie value changes as same session go through different stage (such as before login, after login, logout and log back in, etc) while cookie key stays the same. The easy way is the create desired cookie in joomla by modifying its code (small modification in login/logout stage). Login/Logout functions are located in the standard user component (docroot/component/com_user/controller.php). | + | ==== Joomla Code Change ==== |
| | + | |
| | + | To work with Joomla (cached for either guest visitor or logged-in user), LSWS cache relies on a cookie token to differentiate whether a user is logged in or not. However, Joomla assigns cookie to any user (guest and logged-in). cookie value changes as same session go through different stage (such as before login, after login, logout and log back in, etc) while cookie key stays the same. The easy way is the create desired cookie in joomla by modifying its code (small modification in login/logout stage). Login/Logout functions are located in the standard user component (docroot/component/com_user/controller.php). |
| | | | |
| | The modification is as follows: | | The modification is as follows: |
| | | | |
| | Once test ok, implement rewrite rules to enable LSWS cache for the resources that required caching. | | Once test ok, implement rewrite rules to enable LSWS cache for the resources that required caching. |
| | + | |
| | + | ==== Rewrite rules for LSWS caching ==== |
| | | | |
| | In file joomla_docroot/.htaccess | | In file joomla_docroot/.htaccess |
| | # | | # |
| | RewriteRule p.php - [L] | | RewriteRule p.php - [L] |
| - | RewriteCond %{REQUEST_FILENAME} !-f | + | RewriteCond %{REQUEST_FILENAME} !-f |
| - | RewriteCond %{REQUEST_FILENAME} !-d | + | RewriteCond %{REQUEST_FILENAME} !-d |
| - | RewriteCond %{REQUEST_URI} !^/index.php | + | RewriteCond %{REQUEST_URI} !^/index.php |
| - | RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC] | + | RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC] |
| | RewriteRule (.*) index.php | | RewriteRule (.*) index.php |
| - | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] | + | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] |
| | # | | # |
| | ########## End - Joomla! core SEF Section | | ########## End - Joomla! core SEF Section |
| | # | | # |
| | RewriteRule p.php - [L] | | RewriteRule p.php - [L] |
| - | RewriteCond %{REQUEST_FILENAME} !-f | + | RewriteCond %{REQUEST_FILENAME} !-f |
| - | RewriteCond %{REQUEST_FILENAME} !-d | + | RewriteCond %{REQUEST_FILENAME} !-d |
| | RewriteCond %{REQUEST_URI} !^/index.php | | RewriteCond %{REQUEST_URI} !^/index.php |
| | RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC] | | RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC] |
| | | | |
| | LSWS Cache Policy configuration (Admin Console -> Server/Vhost ->Cache-> Cache Policy). | | LSWS Cache Policy configuration (Admin Console -> Server/Vhost ->Cache-> Cache Policy). |
| | + | |
| | + | ==== LSWS Cache Policies ==== |
| | | | |
| | Cache Policy: | | Cache Policy: |
| | Ignore Request Cache-Control: => Yes | | Ignore Request Cache-Control: => Yes |
| | Ignore Response Cache-Control: => Yes | | Ignore Response Cache-Control: => Yes |
| | + | Enable Private Cache: => Yes |
| | + | Private Cache Expire Time (seconds): => 120 |
| | | | |
| - | To verify if a resource is served out of LSWS cache is simple, just look for "X-LiteSpeed-Cache: hit" in server response header. If the header is present, the resource IS served from LSWS cache. | + | To verify if a resource is served out of LSWS cache is simple, just look for "X-LiteSpeed-Cache: hit,private" in server response header. If the header is present, the resource IS served from LSWS cache. |
| | | | |
| | HTTP/1.1 200 OK | | HTTP/1.1 200 OK |
| | Connection: Keep-Alive | | Connection: Keep-Alive |
| | Keep-Alive: timeout=5, max=100 | | Keep-Alive: timeout=5, max=100 |
| - | **[COLOR="red"]X-LiteSpeed-Cache: hit[/COLOR]** | + | **[COLOR="red"]X-LiteSpeed-Cache: hit,private[/COLOR]** |
| | Content-Length: 6141 | | Content-Length: 6141 |
| | X-Powered-By: PHP/5.2.11 | | X-Powered-By: PHP/5.2.11 |