3 namespace Doctrine\Tests\Common\Cache;
5 use Doctrine\Common\Cache\MemcachedCache;
7 class MemcachedCacheTest extends CacheTest
11 public function setUp()
13 if (extension_loaded('memcached')) {
14 $this->memcached = new \Memcached();
15 $this->memcached->setOption(\Memcached::OPT_COMPRESSION, false);
16 $this->memcached->addServer('127.0.0.1', 11211);
18 $fh = @fsockopen('127.0.0.1', 11211);
20 $this->markTestSkipped('The ' . __CLASS__ .' requires the use of memcache');
23 $this->markTestSkipped('The ' . __CLASS__ .' requires the use of memcache');
27 public function testNoExpire() {
28 $cache = $this->_getCacheDriver();
29 $cache->save('noexpire', 'value', 0);
31 $this->assertTrue($cache->contains('noexpire'), 'Memcache provider should support no-expire');
34 public function testLongLifetime()
36 $cache = $this->_getCacheDriver();
37 $cache->save('key', 'value', 30 * 24 * 3600 + 1);
39 $this->assertTrue($cache->contains('key'), 'Memcached provider should support TTL > 30 days');
42 protected function _getCacheDriver()
44 $driver = new MemcachedCache();
45 $driver->setMemcached($this->memcached);