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

Is it possible assign dynamic connection in "modelsCache" DI for specific or some model?

My company has a large website with mixed hardcode and our own framework but our framework is too old and never developed for a long time.

So, I try to figure out how each popular framework can be fit in our website and I really interesting with Phalcon because of Stand-alone Model/Volt feature which can reuse inside and outside framework (for hardcode area).

Each of structure of Phalcon is very suitable for our need, but we found issue about Caching in the ORM (reference: https://docs.phalcon.io/en/latest/reference/models-cache.html)

Our main cache system is Memcached, and we separate each cache server for services or model, such as:

  • Memcache server 1 for "Novel" model.
  • Memcache server 2 for "Calculator" model.
  • Memcache server 3 for else other model. And we can't find a way to use the same infrastructure logic for Phalcon.

We're stuck with this issue for two days, and we can't hook or inject dynamic connection for specific model in DI named "modelsCache".

So, we really need help for this issue.



34.6k
Accepted
answer
edited Sep '15

You can pass a service name to override modelsCache to have different connections:

$products = Products::find(
    array(
        "cache" => array(
            "service" => "myOtherCache"
        )
    )
);