Question

To be specific, I need to create an array variable that will be used for caching data, but I don't want to use ZF2 Cache Adapter.

I've tried to create a invokable class that would be used to instantiate object of my class that contains methods for setting and getting values from array that is also defined as a property of that class. As far as I understand, service manager treats all services as shared by default, which is supposed to create only one instance off my class when I get the service by service manager method get for the first time. But this doesn't work, if I get that service in different actions in my Controller class, which is what I need to do. So, how am I supposed to achieve this effect? Create an object that is available application-wide?

No correct solution

OTHER TIPS

I had this kind of problem with managing a cart.

My cart is modeled by a CartManager, which is a unique instance for a user (session) and until paiement (cart is persisted in database).

I register my CartManager as a Service to build the first instance, this instance is built during an event handler attached on MvcEvent::EVENT_ROUTE, once built I override the CartManager service with my Instance, this way wherever I call the service, my first instance is served.

Then I persist (session or database) my Instance in an other event handler attached on MvcEvent::EVENT_FINISH.

All the event handlers are attached in Module::onBoostrap()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top