Support for larger size codes (such as SNOMED US Extension codes)
[openemr.git] / gacl / adodb / adodb-memcache.lib.inc.php
blobfc4748a36cb5327cce931bebbada4d2c59df4299
1 <?php
3 // security - hide paths
4 if (!defined('ADODB_DIR')) die();
6 global $ADODB_INCLUDED_MEMCACHE;
7 $ADODB_INCLUDED_MEMCACHE = 1;
9 /*
11 V4.90 8 June 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
12 Released under both BSD license and Lesser GPL library license.
13 Whenever there is any discrepancy between the two licenses,
14 the BSD license will take precedence. See License.txt.
15 Set tabs to 4 for best viewing.
17 Latest version is available at http://adodb.sourceforge.net
21 function &getmemcache($key,&$err, $timeout=0, $host, $port)
23 $false = false;
24 $err = false;
26 if (!function_exists('memcache_pconnect')) {
27 $err = 'Memcache module PECL extension not found!';
28 return $false;
31 $memcache = new Memcache;
32 if (!@$memcache->pconnect($host, $port)) {
33 $err = 'Can\'t connect to memcache server on: '.$host.':'.$port;
34 return $false;
37 $rs = $memcache->get($key);
38 if (!$rs) {
39 $err = 'Item with such key doesn\'t exists on the memcached server.';
40 return $false;
43 $tdiff = intval($rs->timeCreated+$timeout - time());
44 if ($tdiff <= 2) {
45 switch($tdiff) {
46 case 2:
47 if ((rand() & 15) == 0) {
48 $err = "Timeout 2";
49 return $false;
51 break;
52 case 1:
53 if ((rand() & 3) == 0) {
54 $err = "Timeout 1";
55 return $false;
57 break;
58 default:
59 $err = "Timeout 0";
60 return $false;
63 return $rs;
66 function putmemcache($key, $rs, $host, $port, $compress, $debug=false)
68 $false = false;
69 $true = true;
71 if (!function_exists('memcache_pconnect')) {
72 if ($debug) ADOConnection::outp(" Memcache module PECL extension not found!<br>\n");
73 return $false;
76 $memcache = new Memcache;
77 if (!@$memcache->pconnect($host, $port)) {
78 if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port<br>\n");
79 return $false;
82 $rs->timeCreated = time();
83 if (!$memcache->set($key, $rs, $compress, 0)) {
84 if ($debug) ADOConnection::outp(" Failed to save data at the memcached server!<br>\n");
85 return $false;
87 return $true;
90 function flushmemcache($key=false, $host, $port, $debug=false)
92 if (!function_exists('memcache_pconnect')) {
93 if ($debug) ADOConnection::outp(" Memcache module PECL extension not found!<br>\n");
94 return;
97 $memcache = new Memcache;
98 if (!@$memcache->pconnect($host, $port)) {
99 if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port<br>\n");
100 return;
103 if ($key) {
104 if (!$memcache->delete($key)) {
105 if ($debug) ADOConnection::outp("CacheFlush: $key entery doesn't exist on memcached server!<br>\n");
106 } else {
107 if ($debug) ADOConnection::outp("CacheFlush: $key entery flushed from memcached server!<br>\n");
109 } else {
110 if (!$memcache->flush()) {
111 if ($debug) ADOConnection::outp("CacheFlush: Failure flushing all enteries from memcached server!<br>\n");
112 } else {
113 if ($debug) ADOConnection::outp("CacheFlush: All enteries flushed from memcached server!<br>\n");
116 return;