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

Model MetaData reset() method does nothing (FILES)

$di = new FactoryDefault();

$di->setShared('modelsMetadata', function() use($config) {
    $metadata = new Phalcon\Mvc\Model\MetaData\Files([
        'metaDataDir' => $config->application->cacheDir . 'models-meta/'
    ]);

    return $metadata;
});

and then, later...

$di->get('modelsMetadata')->reset();

Does not delete the ORM cache files. Directory and files have been CHMOD 777

phalcon Version => 3.1.2
Build Date => Apr  6 2017 14:20:49
Powered by Zephir => Version 0.9.7-1fae5e50ac

Directive => Local Value => Master Value
phalcon.db.escape_identifiers => On => On
phalcon.db.force_casting => Off => Off
phalcon.orm.events => On => On
phalcon.orm.virtual_foreign_keys => On => On
phalcon.orm.column_renaming => On => On
phalcon.orm.not_null_validations => On => On
phalcon.orm.exception_on_failed_save => Off => Off
phalcon.orm.enable_literals => On => On
phalcon.orm.late_state_binding => Off => Off
phalcon.orm.enable_implicit_joins => On => On
phalcon.orm.cast_on_hydrate => Off => Off
phalcon.orm.ignore_unknown_columns => Off => Off

PHP 7.0.18-1~dotdeb+8.1 (cli) ( NTS )


85.5k

its ->Flush() i think ? can you test that please ?

Nope, it's reset().

Call to undefined method Phalcon\Mvc\Model\MetaData\Files::flush()

Reset "works" - in that the method is actually there, to call, but nothing actually happens.

    /**
     * Resets internal meta-data in order to regenerate it
     * <code>
     * $metaData->reset();
     * </code>
     */
    public function reset() {}

source



85.5k
edited Apr '17

ah for metadata is different...

as you can see the function doesnt delete the files https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/model/metadata.zep#L776

if its just for dev purposes, here is my code


$this->di->set('modelsMetadata', function () use ($config) {

            if ($config->env === 'development') {
                return new \Phalcon\Mvc\Model\Metadata\Memory();
            }

            return new \Phalcon\Mvc\Model\MetaData\Redis([
                'host'     => $config->redis->host,
                'port'     => $config->redis->port,
                "statsKey" => '_shop-model-MetaData-',
                "prefix"   => $config->redis->prefix,
                "index"    => $config->redis->index,
                'lifetime' => $config->redis->bigLifeTime
            ]);
        }, true);


43.9k

Hi,

  1. I've got to say that it's a kind of strange behavior: reset the meta data doesn't clear the cache file !
  2. while using a file cache, why don't you use manual metadata instead ? https://docs.phalcon.io/en/latest/reference/models-metadata.html#manual-metadata . I'm not sure, but got the feeling that it could be more perf efficient.


85.5k

hmm for redis, it seems that it deletes them https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/model/metadata/redis.zep#L132

Dunno what's the idea to be honest.