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

Caching PHP object

Hello, I would like to ask how can I cache my PHP Objects using Phalcon?

I would like to access these objects and change their properties from time to time. I've created my objects in Controller's initialize function, but every time I request something from the controller the properties of the object is changing.

I would like to store my objects in a manner that they will not change if I request something from the Controller.

Thank you in advance.



11.6k

if you don't want to setup a cache like redis or apc, you can use session vars, using "$this->persistent->yourvar = $yourobj" in your controller. this way you will recover your objects accross different action

But remember that persistent works only for the same controller, if you will access it in another controller it won'y be available.