protected function setUp()
 {
     if (!class_exists('\\Onoi\\Cache\\CacheFactory')) {
         $this->markTestSkipped('CacheFactory is not available');
     }
     $cacheFactory = new CacheFactory();
     $this->cache = $cacheFactory->newFixedInMemoryLruCache(500);
 }
Example #2
0
 public function testCanConstructZendCache()
 {
     if (!interface_exists('\\Zend\\Cache\\Storage\\StorageInterface')) {
         $this->markTestSkipped('StorageInterface is not available');
     }
     $cache = $this->getMockBuilder('\\Zend\\Cache\\Storage\\StorageInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $instance = new CacheFactory();
     $this->assertInstanceOf('\\Onoi\\Cache\\ZendCache', $instance->newZendCache($cache));
 }
 public function testCachedQueuedResponse()
 {
     $this->connectToHttpd();
     $expectedToCount = 5;
     $cacheFactory = new CacheFactory();
     $httpRequestFactory = new HttpRequestFactory($cacheFactory->newFixedInMemoryLruCache());
     $asyncCurlRequest = $httpRequestFactory->newAsyncCurlRequest();
     for ($i = 0; $i < $expectedToCount; $i++) {
         $asyncCurlRequest->addHttpRequest($httpRequestFactory->newCachedCurlRequest($this->getHttpdRequestUrl($i)));
     }
     $this->assertCount($expectedToCount, $asyncCurlRequest->execute());
 }
 protected function setUp()
 {
     $cache = array();
     $cacheFactory = new CacheFactory();
     $cache[] = $cacheFactory->newFixedInMemoryLruCache();
     if (class_exists('\\HashBagOStuff')) {
         $cache[] = $cacheFactory->newMediaWikiCache(new HashBagOStuff());
     }
     if (class_exists('\\Doctrine\\Common\\Cache\\ArrayCache')) {
         $cache[] = $cacheFactory->newDoctrineCache(new ArrayCache());
     }
     $this->cache = $cacheFactory->newCompositeCache($cache);
 }
Example #5
0
 /**
  * @since 1.0
  *
  * @param string $namespace
  * @param Cache $cache
  */
 public function __construct($namespace, Cache $cache)
 {
     if (!is_string($namespace)) {
         throw new InvalidArgumentException("Expected the namespace to be a string");
     }
     $this->namespace = $namespace;
     $this->cache = $cache;
     // It is only used internally therefore no injection required as it improves
     // performance on long lists as seen in #1
     $this->internalCache = CacheFactory::getInstance()->newFixedInMemoryLruCache(500);
 }
 protected function setUp()
 {
     if (!class_exists('\\Onoi\\Cache\\CacheFactory')) {
         $this->markTestSkipped('CacheFactory is not available');
     }
     if (!class_exists('\\Redis')) {
         $this->markTestSkipped('Requires redis php-class/extension to be available');
     }
     $redis = new \Redis();
     if (!$redis->connect('127.0.0.1')) {
         $this->markTestSkipped('Cannot connect to redis');
     }
     if (!class_exists('\\Doctrine\\Common\\Cache\\RedisCache')) {
         $this->markTestSkipped('RedisCache is not available');
     }
     $redisCache = new RedisCache();
     $redisCache->setRedis($redis);
     $cacheFactory = new CacheFactory();
     $this->cache = $cacheFactory->newDoctrineCache($redisCache);
 }
 /**
  * @since 2.2
  *
  * @param integer|string $mediaWikiCacheType
  *
  * @return Cache
  */
 public function newMediaWikiCompositeCache($mediaWikiCacheType = null)
 {
     $mediaWikiCache = ObjectCache::getInstance($mediaWikiCacheType === null ? $this->getMainCacheType() : $mediaWikiCacheType);
     $compositeCache = OnoiCacheFactory::getInstance()->newCompositeCache(array($this->newFixedInMemoryCache(500), OnoiCacheFactory::getInstance()->newMediaWikiCache($mediaWikiCache)));
     return $compositeCache;
 }