public function testMultiCacheAliveFirst() { $alifePeer = new SocketMemcached("127.0.0.1", "11211"); //some existing memcached $alifePeer->set('some_key', 'some_value'); $slave1 = new PeclMemcached("35.143.65.241", "11211"); //some not existing memcache $slave2 = new PeclMemcached("165.34.176.221", "11211"); //some not existing memcache $cache = new SequentialCache($alifePeer, array($slave1, $slave1, $slave2)); $result = $cache->get("some_key"); $this->assertEquals($result, 'some_value'); }
/** * @depends testWrongKeys **/ public function testWithTimeout() { $cache = SocketMemcached::create('localhost')->setTimeout(200); $cache->add('a', 'b'); $this->assertEquals($cache->get('a'), 'b'); $cache->clean(); }
public function __construct($host = SocketMemcached::DEFAULT_HOST, $port = SocketMemcached::DEFAULT_PORT, $buffer = SocketMemcached::DEFAULT_BUFFER) { if (PinbaClient::isEnabled()) { PinbaClient::me()->timerStart('memcached_' . $host . '_' . $port . '_connect', array('memcached_connect' => $host . '_' . $port)); } parent::__construct($host, $port, $buffer); if (PinbaClient::isEnabled()) { PinbaClient::me()->timerStop('memcached_' . $host . '_' . $port . '_connect'); } }
public function testCyclicAggregateCache() { $this->doTestMemcached(CyclicAggregateCache::create()->setSummaryWeight(42)->addPeer('first', SocketMemcached::create(), 25)->addPeer('second', PeclMemcached::create(), 1)->addPeer('third', PeclMemcached::create(), 13)); }
<?php // $Id$ require dirname(__FILE__) . '/../../global.inc.php.tpl'; // set up default cache peer Cache::setPeer(SocketMemcached::create()); // or even several aggregated peers Cache::setPeer(AggregateCache::create()->addPeer('memcached daemon at localhost', SocketMemcached::create())->addPeer('local low-priority file system', RubberFileSystem::create('/tmp/onphp-cache'), AggregateCache::LEVEL_VERYLOW)); // let's test out cache system $ts = new Timestamp(time()); $key = 'timestamp_object'; if (Cache::me()->set($key, $ts, 2)) { echo "object is in cache now\n"; if ($cached = Cache::me()->get($key)) { echo "got from cache:\n"; print_r($cached); } } else { echo "failed to store object in cache\n"; }