We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Can't change model meta data caching

I'm trying to setup model meta data caching as suggested in the manual: https://docs.phalcon.io/en/latest/reference/models.html#caching-meta-data

$di->setShared('modelsMetadata', function() {
            // die('never dies here');
            $metaData = new \Phalcon\Mvc\Model\MetaData\Apc(array(
                "lifetime" => 86400,
                "prefix"   => 'my-app'
            ));
            return $metaData;
});

However, it does not work. This service is never called (setting a breakpoint in it or dying does not stop the application there). In my DB query log I still see those meta-data related SQL queries such as:

SELECT TC.COLUMN_NAME, TC.DATA_TYPE, TC.DATA_LENGTH, TC.DATA_PRECISION, TC.DATA_SCALE, TC.NULLABLE, C.CONSTRAINT_TYPE, TC.DATA_DEFAULT, CC.POSITION FROM ALL_TAB_COLUMNS TC LEFT JOIN (ALL_CONS_COLUMNS CC JOIN ALL_CONSTRAINTS C ON (CC.CONSTRAINT_NAME = C.CONSTRAINT_NAME AND CC.TABLE_NAME = C.TABLE_NAME AND CC.OWNER = C.OWNER AND C.CONSTRAINT_TYPE = 'P')) ON TC.TABLE_NAME = CC.TABLE_NAME AND TC.COLUMN_NAME = CC.COLUMN_NAME WHERE TC.TABLE_NAME = 'AC_USER' AND TC.OWNER = 'common' ORDER BY TC.COLUMN_ID

I also tried implementing the getModelsMetaData method in my models but that is never called by Phalcon either.

Using Phalcon 1.2.4, DB is Oracle 10g, PHP 5.4.23, APC 3.1.13.

Are there any additional steps required to configure model meta data caching?

Maybe use set() instead of setShared()

Nope, I tried set() - no luck there. I wonder if perhaps this service is called early on in the application workflow so by the time my service.php is evaluated, the modelsMetadata is never called again. Any ideas?

try to clear apc

btw while developing app you should use memory strategy. Apc is for production enviroment

Of course that Apc is for production - that is why I am looking at it ;-) No, clearing Apc did not help.

Perhaps this is the question for Phalcon developers: why is the modelsMetadata service never called? My code flow is as follows:

// public/index.php
namespace MyApp;
$config = require_once __DIR__ . '/../config/config.php';
try {
    require_once __DIR__ . '/../services/autoload.php';
    $di = require __DIR__ . '/../services/services.php';
    $application = new \Phalcon\Mvc\Application();
    $application->setDI($di);
    echo $application->handle()->getContent();
} catch (\Exception $e) {
    die($e->getMessage());
}

// services/services.php
$di = new \Phalcon\DI\FactoryDefault();
$di->setShared('modelsMetadata', function() {
    die('initializing modelsMetadata service'); // never dies here
});
// the rest of my services including the "db" service are defined below