note 110796 deleted from memcached.callbacks.read-through by aharvey

From: Date: Mon, 10 Dec 2012 00:52:24 +0000
Subject: note 110796 deleted from memcached.callbacks.read-through by aharvey
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192434@lists.php.net to get a copy of this message
Note Submitter: burzumko at gmail dot com ---- My workaround of this stuff: <?php class MyMemcached { static protected $instance; protected $m; private function __construct() { $this->m = new Memcached(); $this->m->addServer('localhost', 11211); } function __call($name, $params) { return call_user_func_array(array($this->m, $name), $params); } private function __clone() {} private function __wakeup() {} public static function getInstance() { if ( is_null(self::$instance) ) { self::$instance = new self(); } return self::$instance; } public function get($key, $time = 0, $callback = null) { $value = $this->m->get($key); if (($value === false) && ($this->m->getResultCode() != Memcached::RES_SUCCESS) && !empty($callback) ) { $value = call_user_func($callback, $this->m, $key); $this->m->set($key, $value, $time); } return $value; } } $m = MyMemcached::getInstance(); var_dump($m->get('foo')); $foo = $m->get('foo', 5, function() { echo "# new value\n"; $new_foo = date('r ') . rand(); return $new_foo; }); var_dump($foo); var_dump($m->get('foo')); ?>

« previous php.notes (#192434) next »