4 if (!defined(
'ADODB_DIR'))
die();
7 $ADODB_INCLUDED_MEMCACHE = 1;
10 if (empty($ADODB_INCLUDED_CSV)) include(ADODB_DIR.
'/adodb-csvlib.inc.php');
53 $this->hosts = $obj->memCacheHost;
54 $this->port = $obj->memCachePort;
55 $this->compress = $obj->memCacheCompress;
61 if (!function_exists(
'memcache_pconnect')) {
62 $err =
'Memcache module PECL extension not found!';
66 $memcache =
new MemCache;
68 if (!is_array($this->hosts)) $this->hosts = array($this->hosts);
71 foreach($this->hosts as
$host) {
72 if (!@$memcache->addServer($host,$this->port,
true)) {
76 if ($failcnt ==
sizeof($this->hosts)) {
77 $err =
'Can\'t connect to any memcache server';
80 $this->_connected =
true;
81 $this->_memcache = $memcache;
86 function writecache($filename, $contents, $debug, $secs2cache)
88 if (!$this->_connected) {
90 if (!$this->
connect($err) && $debug) ADOConnection::outp($err);
92 if (!$this->_memcache)
return false;
94 if (!$this->_memcache->set($filename, $contents, $this->compress ? MEMCACHE_COMPRESSED : 0, $secs2cache)) {
95 if ($debug) ADOConnection::outp(
" Failed to save data at the memcached server!<br>\n");
103 function readcache($filename, &$err, $secs2cache, $rsClass)
106 if (!$this->_connected) $this->
connect($err);
107 if (!$this->_memcache)
return $false;
109 $rs = $this->_memcache->get($filename);
111 $err =
'Item with such key doesn\'t exists on the memcached server.';
120 if (! is_object(
$rs)) {
121 $err =
'Unable to unserialize $rs';
124 if (
$rs->timeCreated == 0)
return $rs;
126 $tdiff = intval(
$rs->timeCreated+$secs2cache - time());
130 if ((rand() & 15) == 0) {
136 if ((rand() & 3) == 0) {
151 if (!$this->_connected) {
153 if (!$this->
connect($err) && $debug) ADOConnection::outp($err);
155 if (!$this->_memcache)
return false;
157 $del = $this->_memcache->flush();
160 if (!$del) ADOConnection::outp(
"flushall: failed!<br>\n");
161 else ADOConnection::outp(
"flushall: succeeded!<br>\n");
168 if (!$this->_connected) {
170 if (!$this->
connect($err) && $debug) ADOConnection::outp($err);
172 if (!$this->_memcache)
return false;
174 $del = $this->_memcache->delete($filename);
177 if (!$del) ADOConnection::outp(
"flushcache: $key entry doesn't exist on memcached server!<br>\n");
178 else ADOConnection::outp(
"flushcache: $key entry flushed from memcached server!<br>\n");
if(isset($_REQUEST['nrows'])) else $rs
ADODB_Cache_MemCache(&$obj)
global $ADODB_INCLUDED_CSV
readcache($filename, &$err, $secs2cache, $rsClass)
writecache($filename, $contents, $debug, $secs2cache)
flushcache($filename, $debug=false)
global $ADODB_INCLUDED_MEMCACHE