2 /** @package verysimple::Util */
3 require_once("verysimple/Phreeze/CacheMemCache.php");
6 * MemCacheProxy provides simple access to memcache pool but ignores
7 * if the server is down instead of throwing an error.
9 * could not be contacted, ServerOffline will be set to true.
11 * @package verysimple::Util
12 * @author VerySimple Inc.
13 * @copyright 1997-2007 VerySimple, Inc.
14 * @license http://www.gnu.org/licenses/lgpl.html LGPL
18 class MemCacheProxy
extends CacheMemCache
20 public $ServerOffline = false;
21 public $LastServerError = '';
24 * Acts as a proxy for a MemCache server and fails gracefull if the pool cannot be contacted
27 * array in host/port format: array('host1'=>'11211','host2'=>'11211')
29 * string a unique string. prevents conflicts in case multiple apps are using the same memcached server bank
31 public function __construct($server_array = array('localhost'=>'11211'), $uniquePrefix = "CACHE-")
33 if (class_exists('Memcache')) {
34 $memcache = new Memcache();
35 foreach (array_keys($server_array) as $host) {
36 // print "adding server $host " . $server_array[$host];
37 $memcache->addServer($host, $server_array [$host]);
40 parent
::__construct($memcache, $uniquePrefix, true);
42 $this->LastServerError
= 'Memcache client module not installed';
43 $this->ServerOffline
= true;
50 public function Get($key, $flags = null)
52 // prevent hammering the server if it is down
53 if ($this->ServerOffline
) {
57 return parent
::Get($key, $flags);
63 public function Set($key, $val, $flags = null, $timeout = 0)
65 // prevent hammering the server if it is down
66 if ($this->ServerOffline
) {
70 return parent
::Set($key, $val, $flags, $timeout);
76 public function Delete($key)
78 // prevent hammering the server if it is down
79 if ($this->ServerOffline
) {
83 return parent
::Delete($key);