Phalcon builds up some information about tables it is using, so it is possible to validate data being inserted to them without implementing everything by hand. Those are meta data for models. To speed up and prevent Phalcon from building Meta Data every time page is refreshed, it is possible to cache them. To do so, you need to implement metaData
service for it to use:
$di->set('modelsMetadata', function() use ($config)
{
// assuming that you have a $config var with
// models.metadata.adapter field declared
switch (strtolower($config->models->metadata->adapter)) {
case 'apc':
$metaData = new MetaDataApcAdapter([
'lifetime' => $config->models->metadata->lifetime,
'suffix' => $config->models->metadata->suffix,
]);
break;
case 'xcache':
$metaData = new MetaDataXCacheAdapter([
'lifetime' => $config->models->metadata->lifetime,
'prefix' => $config->models->metadata->suffix,
]);
break;
case 'memory':
$metaData = new MetaDataMemoryAdapter();
break;
default:
throw new \Exception('Unimplemented models::metadata.adapter in config.ini');
}
return $metaData;
});
Further documentation available at Phalcons' dedicated page.