/**
  * Singleton method for memcache servers
  * 
  * The Servers array should contain arrays of servers (IP and Port)
  *
  * @param array $servers
  * @return memcahed instance
  */
 public static function getMem()
 {
     $servers = self::getServers();
     if (!empty($servers)) {
         if (self::$objMem == NULL) {
             self::$objMem = new Memcache();
             // connect to the memcache server(s)
             foreach ($servers as $cache) {
                 self::$objMem->addServer($cache['ip'], (int) $cache['port']);
             }
         }
     }
     return self::$objMem;
 }
Example #2
0
 /**
  * Method to execute a query against the database
  *
  * @param      string $stmt the SQL query string
  * @return     db     _result|FALSE a PEAR::DB_Result object, or FALSE on failure
  * @deprecated see execute()
  * @access     public
  */
 public function query($stmt)
 {
     if ($this->objMemcache == TRUE) {
         if (chisimbacache::getMem()->get(md5($this->cachePrefix . $stmt))) {
             $cache = chisimbacache::getMem()->get(md5($this->cachePrefix . $stmt));
             $ret = unserialize($cache);
         } else {
             if ($this->debug == TRUE) {
                 log_debug($stmt);
             }
             $ret = $this->_queryAll($stmt);
             if (PEAR::isError($ret)) {
                 $ret = FALSE;
             }
             chisimbacache::getMem()->set(md5($this->cachePrefix . $stmt), serialize($ret), MEMCACHE_COMPRESSED, $this->cacheTTL);
         }
     } elseif ($this->objAPC == TRUE) {
         $ret = apc_fetch($this->cachePrefix . $stmt);
         if ($ret == FALSE) {
             $ret = $this->_queryAll($stmt);
             if (PEAR::isError($ret)) {
                 $ret = FALSE;
             }
             apc_store($this->cachePrefix . $stmt, $ret, $this->cacheTTL);
         }
     } else {
         if ($this->debug == TRUE) {
             log_debug($stmt);
         }
         $ret = $this->_queryAll($stmt);
         if (PEAR::isError($ret)) {
             $ret = FALSE;
         }
     }
     return $ret;
 }
 /**
  * Stores a new key/value pair in the cache. If the key already exists, the value will be overwritten.
  *
  * @access public
  * @param  string $key   The key.
  * @param  string $value The new value.
  */
 public function __set($key, $value)
 {
     // Prepend the site name to the key.
     $key = $this->objAltConfig->getSiteName() . $key;
     // Update the local cache.
     $this->cache[$key] = $value;
     // Update the external cache.
     if ($this->memcache) {
         $value = serialize($value);
         chisimbacache::getMem()->set($key, $value);
     } elseif ($this->apc) {
         apc_store($key, $value);
     }
 }
 public function getGroupInfo($groupid)
 {
     if ($this->objMemcache == TRUE) {
         if (chisimbacache::getMem()->get(md5($this->cachePrefix . getGroupInfo . $groupid))) {
             $cache = chisimbacache::getMem()->get(md5($this->cachePrefix . getGroupInfo . $groupid));
             $ret = unserialize($cache);
         } else {
             $ret = $this->objLuAdmin->perm->getGroups(array('filters' => array('group_id' => $groupid)));
             chisimbacache::getMem()->set(md5($this->cachePrefix . getGroupInfo . $groupid), serialize($ret), MEMCACHE_COMPRESSED, $this->cacheTTL);
         }
     } elseif ($this->objAPC == TRUE) {
         $ret = apc_fetch($this->cachePrefix . getGroupInfo . $groupid);
         if ($ret == FALSE) {
             $ret = $this->objLuAdmin->perm->getGroups(array('filters' => array('group_id' => $groupid)));
             apc_store($this->cachePrefix . getGroupInfo . $groupid, $ret, $this->cacheTTL);
         }
     } else {
         $ret = $this->objLuAdmin->perm->getGroups(array('filters' => array('group_id' => $groupid)));
     }
     return $ret;
 }