Yes, you're right, but the only bad thing is writing:
Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('cache');
v.s.
Zend_Registry::get('cache');and maybe using Zend_Registry is faster? Regards, Saša Stamenković On Tue, Oct 6, 2009 at 5:21 PM, Hector Virgen <[email protected]> wrote: > It probably wouldn't hurt to check in both places. I think you're right and > checking for a bootstrap resource might be better (or clearer to another > developer) than checking Zend_Registry. > The question that comes to mind when running into this code later is "Where > does the cache get initialized?". Zend_Registry gives us no clues as to > where or when that cache was registered, but the bootstrap resource clues us > in to the bootstrap. > > -- > Hector > > > > On Mon, Oct 5, 2009 at 10:59 PM, Саша Стаменковић <[email protected]>wrote: > >> Thx Hector. >> Nice answer and useful code example. >> Is there a reason to use registry over bootstrap init and get resource? >> >> Is it better to do >> >> if (Zend_Registry::has('cache')) { >> $this->setCache(Zend_Registry::get('cache')); >> } >> >> or >> >> if ($cache = $this->setCache(Zend_Registry::get('cache'))) { >> // >> } >> >> Regards, >> Saša Stamenković >> >> >> >> On Mon, Oct 5, 2009 at 8:06 PM, Hector Virgen <[email protected]> wrote: >> >>> If it's system-wide, I usually place it in the registry for easy access. >>> But then I also use a lazy-loading technique in the model layer that pulls >>> the cache from the registry if it wasn't set: >>> public function setCache(Zend_Cache_Core $cache) >>> { >>> $this->_cache = $cache; >>> return $this; >>> } >>> >>> public function getCache() >>> { >>> if (null === $this->_cache) { >>> if (Zend_Registry::has('cache')) { >>> $this->setCache(Zend_Registry::get('cache')); >>> } >>> } >>> return $this->_cache; >>> } >>> >>> -- >>> Hector >>> >>> >>> >>> On Mon, Oct 5, 2009 at 1:03 AM, umpirsky <[email protected]> wrote: >>> >>>> >>>> Hi. >>>> >>>> I need several Zend_Cache objects for my app (file, memcached...), and I >>>> don't want to instantiate and initialize it all over my app. So, there >>>> are 2 >>>> options: >>>> >>>> - Init Zend_Cache in bootstrap and then get it all over app (in models >>>> for >>>> ex) with: >>>> $this->getFrontController()->getParam('bootstrap')->getResource('cache'); >>>> - >>>> if I can do this in models at all? How do I access bootstrap resources >>>> from >>>> outside controllers? >>>> - Init Zend_Cache in bootstrap but store it in Zend_Registry then get it >>>> with Zend_Registry::get('cache'); >>>> >>>> What is better/faster approach and why? >>>> -- >>>> View this message in context: >>>> http://www.nabble.com/Application-Resources-Access-tp25746631p25746631.html >>>> Sent from the Zend Framework mailing list archive at Nabble.com. >>>> >>>> >>> >> >
