Is it bad to call a singleton method many time over and over on a page in PHP?

gazerboy

New Member
In PHP if I create a singleton method for like 5 different caching classes (memcache, apc, session, file, cookie)Then I have a main cache class which basicly routes my set() and get() methods to the appropriate caching class. Now lets say I need to use the session, cookie, memcache, and file cache all on the same page. My main cache class would then need to create a new instance 1 time for each of these cache types using a singleton.SO I would then need to call my singleton methods many times on a page, if I were to set/get 30 different calls to the cache on 1 page, it would call the singleton method that many times.I am wondering if it is bad practice or not very good to keep calling my singleton over and over on a page?UPDATEBelow is some code I have started, in it you can get a better example of what I am trying to do... If I were to add something to memcache 40 times on a page, it would call the singleton method for ym memcache class 40 times \[code\]/*** Set a key/value to cache system.** @param string type of cache to store with* @param string|array keys, or array of values* @param mixed value (if keys is not an array)* @return void*/ public function set($type, $keys, $value = http://stackoverflow.com/questions/2098160/FALSE, $options_arr){ if (empty($keys)) return FALSE; if ( ! is_array($keys)) { $keys = array($keys => $val); } // Pick our Cache system to use switch ($type) { case"memcache": // Cache item to memcache $this->memcache = Memcache::getInstance(); $this->memcache->get($keys, $value, $options); break; case "apc": // Cache item to APC $this->apc = APC::getInstance(); $this->apc->get($keys, $value, $options); break; case "session": // Cache item to Sessions foreach ($keys as $key => $val) { // Set the key $_SESSION[$key] = $val; } break; case "cookie": // Cache item to Cookie break; case "file": // Cache item to File break; }}\[/code\]
 
Back
Top