php - Zend - How to enable cache(MetaData) on session table? ← (PHP, Bootstrap)

Solution:

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:

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

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:

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

Answer



Solution:

You must specify cache named as 'dbMetadataCache' and it will cache metadata of all tables.

Here is a example using APC as a backend

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"

Source