Copyright (c) 2004-2006 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
sfSuperCache plugin
The sfSuperCachePlugin writes your page cache somewhere under your root directory to allow your web server to serve them as fast as possible.
It supports caching by domain name.
Please read the limitations at the end.
Installation
Install the plugin
symfony plugin-install http://plugins.symfony-project.com/sfSuperCachePlugin
Choose a directory to store the cache under your web root
mkdir web/cache
chown apache.apache web/cache
Add sfSuperCacheFilter to your filters
supercache:
class: sfSuperCacheFilter
param:
cache_dir: cache
If your content doesn't change based on the hostname,
you can switch the cache_host parameter to false:
supercache:
class: sfSuperCacheFilter
param:
cache_dir: cache
with_host: false
Replace the 2 following lines in .htaccess
RewriteRule ^$ index.html [QSA]
RewriteRule ^([$1.html [QSA](^.]+)$)
by
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}/%{REQUEST_URI}index.html.php -f
RewriteRule ^(.*) cache/%{HTTP_HOST}/$1index.html.php [L]
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}/%{REQUEST_URI}.html.php -f
RewriteRule ^(.*) cache/%{HTTP_HOST}/$1.html.php [L]
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}/%{REQUEST_URI}.php -f
RewriteRule ^(.*) cache/%{HTTP_HOST}/$1.php [L]
Don't forget to change the "cache" dir name with the one you chose in filters.yml.
If you set with_host to false, also remove %{HTTP_HOST}/ from the rules:
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{DOCUMENT_ROOT}/cache/%{REQUEST_URI}index.html.php -f
RewriteRule ^(.*) cache/$1index.html.php [L]
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{DOCUMENT_ROOT}/cache/%{REQUEST_URI}.html.php -f
RewriteRule ^(.*) cache/$1.html.php [L]
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{DOCUMENT_ROOT}/cache/%{REQUEST_URI}.php -f
RewriteRule ^(.*) cache/$1.php [L]
Clear you cache
symfony cc
You're done.
Known limitations
- your page must ends with the right extension: .html, .xml, ... Because Apache will server these pages, it must be able to guess the content type
- symfony cc won't clear the "super" cache. It is important to clear both cache at the same time.
- no vary support
Changelog
2008-03-07 | 1.0.5
- francois: Added support for cache lifetime (based on
cache.yml settings)
BC break: the signature of cache files has changed. They now end with .php
2007-10-10 | 1.0.4