Zend - 如何在会话表上启用缓存(元数据)?
我使用 Zend_Session_SaveHandler_DbTable 将会话存储在表中,
我的探查器告诉我,在每个页面请求 zend 都会执行以下操作:
# Query Time
(1) connect 0.0032038688659668
(2) DESCRIBE session
0.0041539669036865
(3) SELECT 会话
.* FROM 会话
WHERE (((会话
.session_id
= '7nnan8ltd6h64sigs6dlkicvh0' AND 会话
.save_path
= '' AND session
.name
= 'PHPSESSID'))) 0.00057697296142578
总时间:0.008 秒
,当我在其他设备上查询时表,zend 描述它们一次(第一次访问该表时),然后如果我刷新页面,它只执行没有描述的查询,在会话表上,它在每个页面上描述(因为我使用身份验证...)
如何在会话表上仅缓存元数据?
我目前正在使用这个
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
i am using Zend_Session_SaveHandler_DbTable to store the session in a table
my profiler tells me that on each page request zend does:
# Query Time
(1) connect 0.0032038688659668
(2) DESCRIBE session
0.0041539669036865
(3) SELECT session
.* FROM session
WHERE (((session
.session_id
= '7nnan8ltd6h64sigs6dlkicvh0' AND session
.save_path
= '' AND session
.name
= 'PHPSESSID'))) 0.00057697296142578
Total time : 0.008 sec
when i do queries on other tables, zend DESCRIBEs them once(the first time it access that table), then if i refresh the page it only does the query with no Describe, on the session table it does DESCRIBE on every page (since i use authentication ... )
how can i cache only the metadata on the session table?
i am currently using this
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;
}
this is my config file
...
;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
...
this is my session table
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;
thanks :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无论您在引导程序还是配置文件中初始化会话保存处理程序,请确保首先调用 Zend_Db_Table_Abstract::setDefaultMetadataCache()。
要在配置文件中指定它,请将会话配置放在
;;fine cache stuff
行之后:或者,如果您不想依赖它们在配置文件中的顺序,您可以添加引导类的
_initSession()
方法专门以正确的顺序加载它们:Wherever you are initializing the session save handler, either in the bootstrap or the config file, make sure that you call Zend_Db_Table_Abstract::setDefaultMetadataCache() first.
To specify it in your config file, put the session config after the
;;fine cache stuff
line:Or, if you don't want to rely on their order in the config file, you can add an
_initSession()
method to your bootstrap class that specifically loads them in the correct order:您必须指定名为“dbMetadataCache”的缓存,它将缓存所有表的元数据。
这是使用 APC 作为后端的示例
You must specify cache named as 'dbMetadataCache' and it will cache metadata of all tables.
Here is a example using APC as a backend