Zend_Cache_Frontend_Page is like
Zend_Cache_Frontend_Output but designed for a complete page.
It's impossible to use Zend_Cache_Frontend_Page for caching
only a single block.
On the other hand, the "cache id" is calculated automatically with
$_SERVER['REQUEST_URI'] and (depending on options)
$_GET, $_POST, $_SESSION,
$_COOKIE, $_FILES. More over, you have only
one method to call (start()) because the
end() call is fully automatic when the page is ended.
For the moment, it's not implemented but we plan to add a HTTP conditional system to save bandwidth (the system will send a HTTP 304 Not Modified if the cache is hit and if the browser has already the good version).
Note
This frontend operates by registering a callback function to be called
when the output buffering it uses is cleaned. In order for this to operate
correctly, it must be the final output buffer in the request. To guarantee
this, the output buffering used by the Dispatcher must be
disabled by calling Zend_Controller_Front's
setParam() method, for example,
$front->setParam('disableOutputBuffering', true); or adding
"resources.frontcontroller.params.disableOutputBuffering = true"
to your bootstrap configuration file (assumed INI) if using
Zend_Application.
Table 24. Page Frontend Options
| Option | Data Type | Default Value | Description |
|---|---|---|---|
| http_conditional | Boolean | FALSE |
use the http_conditional system (not implemented for the moment) |
| debug_header | Boolean | FALSE |
if TRUE, a debug text is added before each
cached pages
|
| default_options | Array | array(...see below...) |
an associative array of default options:
|
| regexps | Array | array() |
an associative array to set options only for some
REQUEST_URI, keys are
(PCRE) regexps, values are associative arrays
with specific options to set if the regexp matchs on
$_SERVER['REQUEST_URI'] (see default_options
for the list of available options); if several regexps match the
$_SERVER['REQUEST_URI'], only the last one
will be used
|
| memorize_headers | Array | array() |
an array of strings corresponding to some HTTP headers name. Listed headers will be stored with cache datas and "replayed" when the cache is hit |
Use of Zend_Cache_Frontend_Page is really trivial:
<?php
// [...] // require, configuration and factory
$cache->start();
// if the cache is hit, the result is sent to the browser
// and the script stop here
// rest of the page ...
a more complex example which shows a way to get a centralized cache management in a
bootstrap file (for using with Zend_Controller for example)
<?php
/*
* You should avoid putting too many lines before the cache section.
* For example, for optimal performances, "require_once" or
* "Zend_Loader::loadClass" should be after the cache section.
*/
$frontendOptions = array(
'lifetime' => 7200,
'debug_header' => true, // for debugging
'regexps' => array(
// cache the whole IndexController
'^/$' => array('cache' => true),
// cache the whole IndexController
'^/index/' => array('cache' => true),
// we don't cache the ArticleController...
'^/article/' => array('cache' => false),
// ... but we cache the "view" action of this ArticleController
'^/article/view/' => array(
'cache' => true,
// and we cache even there are some variables in $_POST
'cache_with_post_variables' => true,
// but the cache will be dependent on the $_POST array
'make_id_with_post_variables' => true
)
)
);
$backendOptions = array(
'cache_dir' => '/tmp/'
);
// getting a Zend_Cache_Frontend_Page object
$cache = Zend_Cache::factory('Page',
'File',
$frontendOptions,
$backendOptions);
$cache->start();
// if the cache is hit, the result is sent to the browser and the
// script stop here
// [...] the end of the bootstrap file
// these lines won't be executed if the cache is hit
Because of design issues, in some cases (for example when using non
HTTP 200 return codes), you could need to cancel the current
cache process. So we introduce for this particular frontend, the
cancel() method.
<?php
// [...] // require, configuration and factory
$cache->start();
// [...]
if ($someTest) {
$cache->cancel();
// [...]
}
// [...]




