2

我正在使用 Zend_Session_SaveHandler_DbTable 将会话存储在表中

我的分析器告诉我,在每个页面请求上,zend 都会:

# 查询时间

(1)连接0.0032038688659668

(2) 描述session 0.0041539669036865

(3) SELECT session.* FROM sessionWHERE ((( session. session_id= '7nnan8ltd6h64sigs6dlkicvh0' AND session. save_path= '' AND session. name= 'PHPSESSID'))) 0.00057697296142578

总时间:0.008 秒

当我对其他表进行查询时,zend 对它们进行一次 DESCRIBE(它第一次访问该表时),然后如果我刷新页面它只进行没有描述的查询,在会话表上它会在每个页面上进行 DESCRIBE(因为我使用身份验证...)

我怎样才能只缓存会话表上的元数据?

我目前正在使用这个

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
...

这是我的会话表

CREATE TABLE IF NOT EXISTS `session` (
  `session_id` char(32) NOT NULL,
  `save_path` varchar(32) NOT NULL,
  `name` varchar(32) NOT NULL DEFAULT '',
  `modified` int(11) DEFAULT NULL,
  `lifetime` int(11) DEFAULT NULL,
  `session_data` text,
  PRIMARY KEY (`session_id`,`save_path`,`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

感谢:D

4

2 回答 2

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');
}
于 2011-06-01T19:32:02.220 回答
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"
于 2011-06-01T09:48:07.507 回答