Zend Framework page cache instance
- 2021-07-06 10:15:12
- OfStack
1 Create a cache object using a factory approach: Zend_Cache:: factory ().
The Zend_Cache:: factory method has four parameters: front-end type, back-end type, front-end parameter, and back-end parameter.
The following is an example of page caching:
class Zend_Controller_Shawn extends Zend_Controller_Action
{
public static $cache;
public function init()
{
$frontendOptions = array(
'lifetime' => 3600, // Cache lifetime
'debug_header' => true, // true Is open debug Usually set to false
'regexps' => array(
'^/$' => array('cache' => true), // All pages are cached
'^/index/' => array('cache' => true), // Cache index Under all action Page
'^/index/search' => array('cache' => false), // Right search action Not caching
),
'default_options' => array(
'cache_with_get_variables' => true,
'cache_with_post_variables' => true,
'make_id_with_cookie_variables' => true, // Note that if it is opened, session To open this
'cache_with_session_variables' => true, // Note that if it is opened, session To open this
'cache_with_files_variables' => true,
'cache_with_cookie_variables' => true, // Note that if it is opened, session To open this
)
);
$backendOptions = array('cache_dir' => 'C:/www/zend/cache/'); // Cache storage path, which must exist and be writable
self::$cache = Zend_Cache::factory('Page', 'File', $frontendOptions, $backendOptions);
self::$cache->start(); // Start caching
// If necessary, you can clean up the cache on other pages
Zend_Controller_Shawn::$cache->clean(Zend_Cache::CLEANING_MODE_ALL);
}
}
For more details, please refer to the official manual of Zend, http://framework.zend.com/manual/1. 12/en/zend.cache.frontends.html