Php Zend-如何在会话表上启用缓存(元数据)?

Php Zend-如何在会话表上启用缓存(元数据)?,php,zend-framework,session,cache-control,Php,Zend Framework,Session,Cache Control,我使用Zend_Session_SaveHandler_DbTable将会话存储在一个表中 我的探查器告诉我,zend在每个页面请求时都会: 查询时间 1连接0.0032038688659668 2描述课时0.0041539669036865 3从会话中选择session.*其中session.session_id='7nnan8ltd6h64sigs6dlkicvh0'和session.save_path=以及session.name='PHPSESSID'0.0005769729614257

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

我的探查器告诉我,zend在每个页面请求时都会:

查询时间

1连接0.0032038688659668

2描述课时0.0041539669036865

3从会话中选择session.*其中session.session_id='7nnan8ltd6h64sigs6dlkicvh0'和session.save_path=以及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

您必须指定名为“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"

无论在引导文件还是配置文件中初始化会话保存处理程序,请确保首先调用Zend_Db_Table_Abstract::setDefaultMetadataCache

要在配置文件中指定它,请将会话配置放在;;精细缓存填充行:

或者,如果您不想依赖它们在配置文件中的顺序,可以向引导类添加一个_initSession方法,专门按照正确的顺序加载它们:

protected function _initSession()
{
    $this->bootstrap('cache');
    $this->bootstrap('session');
}

您在哪里定义会话保存处理程序?如果要在配置文件中执行此操作,请确保首先执行缓存定义。否则,在创建会话的Zend_Db_表对象时,没有可用的默认元数据缓存。@squirrel您是对的,我所要做的就是添加一个行保护函数_initSession{$this->bootstrap'cache';,如果您要发布您的答案,我会将其指定为正确答案,以便为您提供奖励:如果我更改配置文件$cache=$bootstrap->getResource'cache';$container=$cache->load$cacheKey,则Dit会破坏此选项;使用缓存管理器,您可以指定多个缓存实例。每个实例都可以使用不同的backend等。然后您可以按如下方式获取指定的缓存名称。$manager=$bootstrap->getResource'cachemanager';$manager->getCache$cacheNameSorry。我忘了添加“resources.db.defaultMetadataCache”项。我非常感谢您的帮助,但我不得不更改4个文件,但仍然出现错误…未捕获异常“Zend_Exc”eption'with message'No entry is registed for key'cache我更喜欢squirrel的解决方案,在这里我添加了一行,一切都正常:DHmmm…我不知道您在注册表中对缓存还做了什么。如果您添加上面的行并从资源类中删除行Zend_Db_Table_Abstract::setDefaultMetadataCache$cache;它应该记住将dbMetadataCache属性编辑为正确的属性。
protected function _initSession()
{
    $this->bootstrap('cache');
    $this->bootstrap('session');
}