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

How do i use cache in ORM?

I want to use cache in the Model class deriectly.How do i write the code ?



4.3k

Yes.I read that, but i am a little confused about 'modelsCache' service. Once you setup that service, how do i destroy cache when i update or delete models.Use events like beforeSave? And i want use \Phalcon\Cache\Backend\File CLASS in the Model's STATIC function find and findFirst, how do i setup that. @Karol Marcinkiewicz you're a kind person, thanks a lot. These questions are too naive, THANKS you again for your patient.



40.8k
Accepted
answer
edited Oct '14

Think if you really need to cache ORM, maybe caching view layer will work better? Your cache key could be md5($_SERVER['REQUEST_URI'])

But if you need to cache ORM, you need to invalidate cache beforeSave(), or beforeUpdate() events like you told. This forum is cached, so best for you would be read source code.

Here is setup for File Backend Cache:

Create your application that it works properly without caching, and then if it is needed fix bottleneck by cache views, views parts and ORM