Apc.class.php
2.19 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
class Util_Cache_Adapter_Apc {
/**
* 判断是否开启了apc.enabled选项
*
* 用来取代 isEnabed
*
* @return boolean
* @since 0.2.1
*/
public static function isEnabled() {
$cache = defined('UTIL_APC_CACHE') ? UTIL_APC_CACHE : true;
if($cache) {
return ( bool ) ini_get ( "apc.enabled" );
} else {
return false;
}
}
/**
* 存入
*
* @param String $key
* @param mixed $value
* @param integer $expire
* @return boolean
*/
public static function set($key, $value, $expire = 7200) {
return apc_store ( $key, $value, $expire );
}
/**
* 取出
*
* @param String $key
* @return unknown
*/
public static function get($key) {
return apc_fetch ( $key );
}
/**
* 删除
*
* @param String $key
* @param integer $delay
* @return bool
*/
public static function delete($key, $delay = 0) {
return apc_delete ( $key );
}
/**
* 减1
*
* @param String $key
* @return unknown
*/
public static function decrement($key, $num = 1) {
$val = self::get ( $key );
if (! empty ( $val ) && is_int ( $val )) {
$val = $val - $num;
self::set ( $val - $num );
}
return $val;
}
/**
* 加1
*
* @param String $key
* @return unknown
*/
public static function increment($key, $num = 1) {
$val = self::get ( $key );
if (! empty ( $val ) && is_int ( $val )) {
$val = $val + $num;
self::set ( $val + $num );
}
return $val;
}
/**
* 清除
*
* @param bool $expired
* @return bool
*/
public static function clear($expired = false) {
if (! $expired) {
return apc_clear_cache ( "user" );
}
$users = apc_cache_info ( "user" );
$list = $users ["cache_list"];
if (! empty ( $list )) {
foreach ( $list as $item ) {
self::delete ( $item ["info"] );
}
}
return true;
}
/**
* 缓存一个文件
*
* @param String $filename
* @return unknown
*/
public static function compileFile($filename) {
return apc_compile_file ( $filename );
}
/**
* 存
*
* @param String $key
* @param unknown_type $value
* @param integer $ttl
* @return unknown
*/
public static function add($key, $value, $ttl = 3600) {
return apc_add ( $key, $value, $ttl );
}
}
?>