Zend Framework is decoupled, so it’s possible to use only the needed features.
I had to improve the performances of an old site, with no cache at all. Changing all the database/file_get_contents requests would have been a long process, so I decided to enable the cache of the web pages with Zend Framework  FrontEnd Page Cache using only few lines of code at the beginning of each page.
That web site uses a header file so I placed there the code only once.
In case there are multiple files, a solution (not tested) could be placing this code in a separate file, then prepend it to all the script thanks to a .htaccees directive:
php_value auto_prepend_file "page_cache.php"
My working example (for my purposes, pages cached if there are variables in $_GET and $_COOKIE and the cache id depends on them, 2 level directories cache, 2h expires time):
// place before any output is started in the "header" script
set_include_path('./zend/library');
require_once 'Zend/Cache.php';
$cache = Zend_Cache::factory(
'Page',
'File',
array(
'lifetime' => 7200,
'ignore_user_abort' => true,
'default_options' => array (
'cache_with_get_variables' => true,
'cache_with_cookie_variables' => true,
'make_id_with_get_variables' => true,
'make_id_with_cookie_variables' => true,
)
),
array(
'cache_dir' => './cache',
'hashed_directory_level' => 2
)
);
$cache->start();
// ... site content...
RSS Feed
Twitter
Posted in 
[...] Improve performances of any web site: cache pages with Zend Framework [...]
This is great little code to re-vitalise your web site.
[...] Even though you have optimised the code, you still have to bootstrap and run the zend application, and the whole process takes time (dispatching, controller logic, scripts render). An interesting solution is caching the whole HTML as a result of the processing (see another post about caching HTML pages of a generic website). [...]
Do you have any experience with invalidating the cache at a page or controller level?
@Stephen
On all the application I’ve worked, I found that the caching should be done at two levels:
- slow sources (db, remote sources like REST requests)
- page cache (pre boostrap with zend, or apache level with reverse proxies / nginx)
I do not see advantages in act in intermediate position (including the controller level)