Highway to PSR2
[openemr.git] / portal / patient / fwk / libs / verysimple / Util / MemCacheProxy.php
blob7042f10fda7c6f7e04acedde8b0e125cf6ffb40e
1 <?php
2 /** @package verysimple::Util */
3 require_once("verysimple/Phreeze/CacheMemCache.php");
5 /**
6 * MemCacheProxy provides simple access to memcache pool but ignores
7 * if the server is down instead of throwing an error.
8 * if the server
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
15 * @version 1.0
18 class MemCacheProxy extends CacheMemCache
20 public $ServerOffline = false;
21 public $LastServerError = '';
23 /**
24 * Acts as a proxy for a MemCache server and fails gracefull if the pool cannot be contacted
26 * @param
27 * array in host/port format: array('host1'=>'11211','host2'=>'11211')
28 * @param
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);
41 } else {
42 $this->LastServerError = 'Memcache client module not installed';
43 $this->ServerOffline = true;
47 /**
48 * @inheritdocs
50 public function Get($key, $flags = null)
52 // prevent hammering the server if it is down
53 if ($this->ServerOffline) {
54 return null;
57 return parent::Get($key, $flags);
60 /**
61 * @inheritdocs
63 public function Set($key, $val, $flags = null, $timeout = 0)
65 // prevent hammering the server if it is down
66 if ($this->ServerOffline) {
67 return null;
70 return parent::Set($key, $val, $flags, $timeout);
73 /**
74 * @inheritdocs
76 public function Delete($key)
78 // prevent hammering the server if it is down
79 if ($this->ServerOffline) {
80 return null;
83 return parent::Delete($key);