caching model metadata simple example

Hi There,

I'm new here, i'm facing problem with default call to "all_tab_columns" Oracle DB process consuming 90% CPU at application peak time, need simple and sample code snippet to implement cache using with memcache or any other cache mechanism

Thanks! in advance

edited Jul '19

Try this at Your startup / bootstrap:

new \Phalcon\Di\FactoryDefault();
$di = \Phalcon\di::getDefault();

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

$metaData = new Phalcon\Mvc\Model\Metadata\Libmemcached(
    [
        "servers" => [
            [
                "host"   => "localhost",
                "port"   => 11211,
                "weight" => 1,
            ],
        ],
        "client" => [
            \Memcached::OPT_HASH       => \Memcached::HASH_MD5,
            \Memcached::OPT_PREFIX_KEY => "prefix.",
        ],
        "lifetime" => 3600,
        "prefix"   => "my_",
    ]
);

return $metadata;
});

..and read: https://docs.phalcon.io/3.4/en/api/phalcon_mvc_model_metadata

edited Jul '19

Thanks!

Do i need to do anything else other than adding above code to service/startup/bootstrap? i mean should i add anything in my model class?

Thanks!

Do i need to do anything else other than adding above code to service/startup/bootstrap? i mean should i add anything in my model class?

No, it should do the job

Thanks! #Tomasz Zadora let me try this.. by the way version wont be a problem for this i believe, because i'm using "1.3"

Version may be a problem, switching to ver. 3.4 is recommended