コード例 #1
0
 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');
 }
コード例 #2
0
 /**
  * @depends testWrongKeys
  **/
 public function testWithTimeout()
 {
     $cache = SocketMemcached::create('localhost')->setTimeout(200);
     $cache->add('a', 'b');
     $this->assertEquals($cache->get('a'), 'b');
     $cache->clean();
 }
コード例 #3
0
 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');
     }
 }
コード例 #4
0
 public function testCyclicAggregateCache()
 {
     $this->doTestMemcached(CyclicAggregateCache::create()->setSummaryWeight(42)->addPeer('first', SocketMemcached::create(), 25)->addPeer('second', PeclMemcached::create(), 1)->addPeer('third', PeclMemcached::create(), 13));
 }
コード例 #5
0
<?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";
}