gpt4 book ai didi

php - Zend - 如何在 session 表上启用缓存(元数据)?

转载 作者:行者123 更新时间:2023-12-04 06:32:07 29 4
gpt4 key购买 nike

我正在使用 Zend_Session_SaveHandler_DbTable 将 session 存储在表中

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

# 查询时间

(1) 连接 0.0032038688659668

(2) 描述 session 0.0041539669036865

(3)选择session。* FROM session WHERE(((sessionsession_id = '7nnan8ltd6h64sigs6dlkicvh0' AND sessionsave_path = '' AND sessionname = 'PHPSESSID')))0.00057697296142578

总时间:0.008 秒

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

如何在 session 表上仅缓存 元数据

我目前正在使用这个

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

这是我的 session 表
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

最佳答案

无论您在 bootstrap 还是配置文件中初始化 session 保存处理程序,请确保首先调用 Zend_Db_Table_Abstract::setDefaultMetadataCache()。

要在您的配置文件中指定它,请将 session 配置放在 ;;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');
}

关于php - Zend - 如何在 session 表上启用缓存(元数据)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5271018/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com