note 110796 added to memcached.callbacks.read-through

From: Date: Sun, 09 Dec 2012 12:43:15 +0000
Subject: note 110796 added to memcached.callbacks.read-through
Groups: php.notes 
Request: Send a blank email to php-notes+get-192430@lists.php.net to get a copy of this message
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')); ?> ---- Server IP: 69.147.83.199 Probable Submitter: 72.52.91.2 (proxied: 176.212.232.35) ---- Manual Page -- http://php.net/manual/en/memcached.callbacks.read-through.php Edit -- https://master.php.net/note/edit/110796 Del: integrated -- https://master.php.net/note/delete/110796/integrated Del: useless -- https://master.php.net/note/delete/110796/useless Del: bad code -- https://master.php.net/note/delete/110796/bad+code Del: spam -- https://master.php.net/note/delete/110796/spam Del: non-english -- https://master.php.net/note/delete/110796/non-english Del: in docs -- https://master.php.net/note/delete/110796/in+docs Del: other reasons-- https://master.php.net/note/delete/110796 Reject -- https://master.php.net/note/reject/110796 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#192430) next »