Exemple #1
0
 protected function init($args)
 {
     parent::init($args);
     $this->mem = new Memcache();
     if (!isset($args['CACHE_HOST'])) {
         throw new KurogoConfigurationException("Memcache host is not defined");
     } else {
         $hosts = $args['CACHE_HOST'];
         if (!is_array($hosts)) {
             $hosts = array($hosts);
         }
     }
     if (!isset($args['CACHE_PORT'])) {
         $port = 11211;
     } else {
         $port = $args['CACHE_PORT'];
         if (is_array($port)) {
             $portSize = count($port);
             $hostsSize = count($hosts);
             if ($hostsSize >= $portSize) {
                 // pad the ports array with the last value to match hosts array size
                 $port = array_pad($port, $hostsSize, $port[$portSize - 1]);
             }
         }
     }
     if (!isset($args['CACHE_PERSISTENT'])) {
         $persistent = false;
     } else {
         $persistent = (bool) $args['CACHE_PERSISTENT'];
     }
     if (!isset($args['CACHE_TIMEOUT'])) {
         $timeout = 1;
     } else {
         $timeout = (int) $args['CACHE_TIMEOUT'];
     }
     if (isset($args['CACHE_COMPRESSED'])) {
         $this->setCompressed($args['CACHE_COMPRESSED']);
     } else {
         $this->setCompressed(true);
     }
     if (isset($args['CACHE_DEBUG'])) {
         $this->setDebug($args['CACHE_DEBUG']);
     } else {
         $this->setDebug(false);
     }
     foreach ($hosts as $index => $host) {
         if (is_array($port)) {
             $result = @$this->mem->addServer($host, $port[$index], $persistent, 1, $timeout);
         } else {
             $result = @$this->mem->addServer($host, $port, $persistent, 1, $timeout);
         }
         if (!$result) {
             throw new KurogoConfigurationException("Memcache server {$host} not available");
         }
     }
 }
Exemple #2
0
 public static function getCacheClasses()
 {
     includePackage('Cache');
     return KurogoMemoryCache::getCacheClasses();
 }
Exemple #3
0
 public function cacher()
 {
     if (!isset($this->cacher)) {
         if ($cacheClass = Kurogo::arrayVal($this->initArgs, 'CACHE_CLASS')) {
             $this->cacher = KurogoMemoryCache::factory($cacheClass, $this->initArgs);
         } else {
             $this->cacher = false;
         }
     }
     return $this->cacher;
 }