当前位置: 首页>>代码示例>>PHP>>正文


PHP CacheProvider::setMemcache方法代码示例

本文整理汇总了PHP中Doctrine\Common\Cache\CacheProvider::setMemcache方法的典型用法代码示例。如果您正苦于以下问题:PHP CacheProvider::setMemcache方法的具体用法?PHP CacheProvider::setMemcache怎么用?PHP CacheProvider::setMemcache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\Common\Cache\CacheProvider的用法示例。


在下文中一共展示了CacheProvider::setMemcache方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: selectDriver

 public function selectDriver($config)
 {
     $cache_engine = $config['cache-engine'];
     //redis, apc, memcache, memcached e xcache
     switch ($cache_engine) {
         case 'redis':
             if (!extension_loaded('redis')) {
                 throw new \Exception("Extensão para {$cache_engine} não encontrada");
             }
             $redis = new \Redis();
             $redis->connect($config['cache-config']['host'], $config['cache-config']['port']);
             $this->driver = new RedisCache();
             $this->driver->setRedis($redis);
             break;
         case 'apc':
             if (!extension_loaded('apc')) {
                 throw new \Exception("Extensão para {$cache_engine} não encontrada");
             }
             $this->driver = new ApcCache();
             break;
         case 'memcache':
             if (!extension_loaded('memcache')) {
                 throw new \Exception("Extensão para {$cache_engine} não encontrada");
             }
             $memcache_config = new \Memcache();
             $memcache_config->connect($config['cache-config']['host'], $config['cache-config']['port']);
             $this->driver = new MemcacheCache();
             $this->driver->setMemcache($memcache_config);
             break;
         case 'memcached':
             if (!extension_loaded('memcache')) {
                 throw new \Exception("Extensão para {$cache_engine} não encontrada");
             }
             $memcached = new \Memcached();
             $memcached->addServer($config['cache-config']['host'], $config['cache-config']['port']);
             $this->driver = new MemcachedCache();
             $this->driver->setMemcached($memcached);
             break;
         case 'xcache':
             if (!extension_loaded('xcache')) {
                 throw new Exception("Extensão para {$cache_engine} não encontrada");
             }
             $this->driver = new XcacheCache();
             break;
         default:
             throw new \Exception('O driver especificado não foi encontado.');
     }
 }
开发者ID:anna-framework,项目名称:anna,代码行数:48,代码来源:Cache.php

示例2: decorateWithConnectable

 /**
  * @param CacheProvider $cacheProvider
  *
  * @return CacheProvider
  */
 protected function decorateWithConnectable(CacheProvider $cacheProvider)
 {
     $memcache = $this->getMemcacheAdapter();
     $settings = $this->config->getSettings();
     $memcache->connect($settings['host'], $settings['port']);
     $cacheProvider->setMemcache($memcache);
     return $cacheProvider;
 }
开发者ID:pcelta,项目名称:doctrine-cache-factory,代码行数:13,代码来源:MemcacheFactory.php

示例3: buildMemcacheCache

 private function buildMemcacheCache()
 {
     if (null === $this->host) {
         throw new HostShouldBeProvidedException();
     }
     if (null === $this->port) {
         $this->port = Memcache::DEFAULT_PORT;
     }
     if (null === $this->timeout) {
         $this->timeout = Memcache::DEFAULT_TIMEOUT;
     }
     $this->server->addserver($this->host, $this->port, null, null, $this->timeout);
     $this->cacheProvider->setMemcache($this->server);
 }
开发者ID:openclassrooms,项目名称:cache,代码行数:14,代码来源:CacheProviderBuilder.php

示例4: getCacheDriver

 /**
  * Get cache driver instance
  *
  * @return \Doctrine\Common\Cache\CacheProvider
  */
 public function getCacheDriver()
 {
     if (!is_null($this->cacheDriver)) {
         return $this->cacheDriver;
     }
     if (php_sapi_name() === 'cli') {
         return $this->cacheDriver = new \Doctrine\Common\Cache\ArrayCache();
     }
     try {
         switch ($this->systemPreferences->get('DBCacheEngine', 'Array')) {
             case 'apc':
                 $this->cacheDriver = new \Doctrine\Common\Cache\ApcCache();
                 break;
             case 'memcache':
                 $memcache = new \Memcache();
                 $memcache->connect($this->systemPreferences->get('DBCacheEngineHost', '127.0.0.1'), $this->systemPreferences->get('DBCacheEnginePort', '11211'));
                 $this->cacheDriver = new \Doctrine\Common\Cache\MemcacheCache();
                 $this->cacheDriver->setMemcache($memcache);
                 break;
             case 'memcached':
                 $memcached = new \Memcached();
                 $memcached->addServer($this->systemPreferences->get('DBCacheEngineHost', '127.0.0.1'), $this->systemPreferences->get('DBCacheEnginePort', '11211'));
                 $this->cacheDriver = new \Doctrine\Common\Cache\MemcachedCache();
                 $this->cacheDriver->setMemcached($memcached);
                 break;
             case 'xcache':
                 $this->cacheDriver = new \Doctrine\Common\Cache\XcacheCache();
                 break;
             case 'redis':
                 $redis = new \Redis();
                 $redis->connect($this->systemPreferences->get('DBCacheEngineHost', '127.0.0.1'), $this->systemPreferences->get('DBCacheEnginePort', '6379'));
                 $this->cacheDriver = new \Doctrine\Common\Cache\RedisCache();
                 $this->cacheDriver->setRedis($redis);
                 break;
             default:
                 $this->cacheDriver = new \Doctrine\Common\Cache\ArrayCache();
                 break;
         }
     } catch (\Exception $e) {
         $this->cacheDriver = new \Doctrine\Common\Cache\ArrayCache();
     }
     return $this->cacheDriver;
 }
开发者ID:alvsgithub,项目名称:Newscoop,代码行数:48,代码来源:CacheService.php


注:本文中的Doctrine\Common\Cache\CacheProvider::setMemcache方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。