I need to save a result in controller returned by the Model. The results should be save in a way that I can use this data when second time controller is called without calling the model. I don’t want to put the data in session or memcache. What should be the most efficient way to do it?
Share
Most people who started with PHP wouldn’t call those “Static Variables.” Did you migrate from Java by chance? It’s a bit of a paradigm shift if you’re switching to the statelessness of HTTP–memcached was designed for this (though I’m not sure APC or other opcode caches were). Cookie-based sessions were kind of designed for this.
If you’re trying to avoid repeat queries on the same request, rely on CI’s query cache (and your database server’s query cache, for that matter), or use what PHP calls “static variables”:
You might have to adjust if the query could possibly return empty, but you get the point. It’s also somewhat unnecessary with models, as I don’t think you can create more than one instance through the CI_Loader anyway…