我正在使用Zend_Session_SaveHandler_DbTable将会话存储在表中
我的探查器告诉我,每个页面请求zend都会:
#查询时间
(1)连接0.0032038688659668
(2)DESCRIBE session
0.0041539669036865
(3)SELECT session
。* FROM session
WHERE(({session
。session_id
='7nnan8ltd6h64sigs6dlkicvh0'和session
。{{1} } =''AND save_path
。session
='PHPSESSID')))0.00057697296142578
总时间:0.008秒
当我对其他表进行查询时,zend DESCRIBEs一次(第一次访问该表),然后如果我刷新页面它只进行没有描述的查询,在会话表上它会在每个页面上进行DESCRIBE (因为我使用身份验证......)
如何在会话表中缓存仅元数据?
我目前正在使用此
name
这是我的配置文件
class Gestionale_Application_Resource_Cache extends Zend_Application_Resource_ResourceAbstract{
public function init ()
{
$options = $this->getOptions();
// Get a Zend_Cache_Core object
//valori che vengono presi dal file di configurazione
$cache = Zend_Cache::factory(
$options['frontEnd'],
$options['backEnd'],
$options['frontEndOptions'],
$options['backEndOptions']);
Zend_Registry::set('cache', $cache);
Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);//per mettere in cache la meta-info
return $cache;
}
这是我的会话表
...
;cache stuff
resources.cache.frontEnd = core
resources.cache.backEnd = file
resources.cache.frontEndOptions.lifetime = 1200 ; in secondi
resources.cache.frontEndOptions.automatic_serialization = true
resources.cache.backEndOptions.lifetime = 3600 ; in secondi
resources.cache.backEndOptions.cache_dir = APPLICATION_PATH "/../cache"
pluginPaths.Gestionale_Application_Resource = APPLICATION_PATH "/../library/Gestionale/Application/Resource"
;;fine cache stuff
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.db.params.charset = "utf8"
resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = ""
resources.db.params.dbname = "gestionale"
resources.db.isDefaultTableAdapter = true
autoloaderNamespaces[] = "Gestionale_";serve per caricare il plugin di sotto quando si usa anche ZFdebug
resources.frontController.plugins.acl = "Gestionale_Controller_Plugin_Acl"
resources.db.params.profiler = true
...
谢谢:D
答案 0 :(得分:2)
无论您在引导程序还是配置文件中初始化会话保存处理程序,请确保首先调用Zend_Db_Table_Abstract :: setDefaultMetadataCache()。
要在配置文件中指定它,请将会话配置放在;;fine cache stuff
行之后:
...
;cache stuff
resources.cache.frontEnd = core
resources.cache.backEnd = file
resources.cache.frontEndOptions.lifetime = 1200 ; in secondi
resources.cache.frontEndOptions.automatic_serialization = true
resources.cache.backEndOptions.lifetime = 3600 ; in secondi
resources.cache.backEndOptions.cache_dir = APPLICATION_PATH "/../cache"
pluginPaths.Gestionale_Application_Resource = APPLICATION_PATH "/../library/Gestionale/Application/Resource"
;;fine cache stuff
resources.session.saveHandler.class = "Zend_Session_SaveHandler_DbTable"
resources.session.saveHandler.options.name = "session"
resources.session.saveHandler.options.primary[] = "session_id"
resources.session.saveHandler.options.primary[] = "save_path"
resources.session.saveHandler.options.primary[] = "name"
resources.session.saveHandler.options.primaryAssignment[] = "sessionId"
resources.session.saveHandler.options.primaryAssignment[] = "sessionSavePath"
resources.session.saveHandler.options.primaryAssignment[] = "sessionName"
resources.session.saveHandler.options.modifiedColumn = "modified"
resources.session.saveHandler.options.dataColumn = "session_data"
resources.session.saveHandler.options.lifetimeColumn = "lifetime"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.db.params.charset = "utf8"
...
或者,如果您不想依赖配置文件中的顺序,可以向引导类添加_initSession()
方法,以正确的顺序加载它们:
protected function _initSession()
{
$this->bootstrap('cache');
$this->bootstrap('session');
}
答案 1 :(得分:1)
您必须指定名为' dbMetadataCache'的缓存。它将缓存所有表的元数据。
以下是使用APC作为后端的示例
resources.cachemanager.dbMetadataCache.frontend.name = "Core"
resources.cachemanager.dbMetadataCache.frontend.options.automatic_serialization = 1
resources.cachemanager.dbMetadataCache.frontend.options.caching = 1
resources.cachemanager.dbMetadataCache.backend.name = "Apc"
resources.db.defaultMetadataCache = "dbMetadataCache"