-
Notifications
You must be signed in to change notification settings - Fork 4
/
mcache.php
86 lines (76 loc) · 2.03 KB
/
mcache.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
class mcache extends Memcache
{
public $def_host = 'localhost';
public $def_port = '12000';
public function __construct($host = null,$port = null){
$host = isset($host)?$host:$this->def_host;
$port = isset($port)?$port:$this->def_port;
if(!$this->connect($host,$port)){
return false;
}
}
public function _get($name,$val=null){
$this->Fkey = false;
$name = isset($val['0'])?$name.'_'.$val['0']:$name;
return $this->get($name);
}
public function _set($name,$val=null){
$name = isset($val['1'])?$name.'_'.$val['1']:$name;
if(isset($val['0']))$this->set($name,$val['0']);
$this->Fkey = false;
return $this;
}
public function _rep($name,$val=null){
$name = isset($val['1'])?$name.'_'.$val['1']:$name;
if(isset($val['0']))$this->replace($name,$val['0']);
$this->Fkey = false;
return $this;
}
public function _del($name,$val=null){
$name = isset($val['0'])?$name.'_'.$val['0']:$name;
$this->delete($name);
$this->Fkey = false;
return $this;
}
public function _inc($name,$val=null){
if($this->increment($name)===false){
$num = isset($val['0'])?$val['0']:1;
$this->set($name,$num);
}
$this->Fkey = false;
return $this->get($name);
}
public function _dec($name,$val=null){
if($this->decrement($name)===false){
$num = isset($val['0'])?$val['0']:0;
$this->set($name,$num);
}
$this->Fkey = false;
return $this->get($name);
}
public function Error($name,$val){
$this->Fkey = false;
$Error = "Fatal error: ";
$Error .= "Call to undefined method ";
$Error .= __class__."::".$name."()\r\n";
throw new Exception($Error);
}
public $Fkey = false;
public function __call($name,$val=null){
if($this->Fkey===false){
$this->Fkey = $name;
$uname = substr($name,3);
$function = '_'.substr($name,0,3);
return $this->$function($uname,$val);
}else return $this->Error($this->Fkey,$val);
}
public static $_instance;
public static function getInstance()
{
if(null === self::$_instance) {
self::$_instance = new self();
}
return self::$_instance;
}
}