Data.class.php
1.64 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
<?php
/**
* 数据级缓存(存储内容小于1MB)
*
* @name QLib_Utils_Cache_Data
* @package Lib/Utils/Cache
* @author whb whb@yoho.cn
* @since 1.0
*/
class Lib_Utils_Cache_Data
{
private static $_key = 'yh_cache_data_';
private static $_cache = null;
private static $_options = array('domain' => 'yoho', 'class' => 'text');
/**
* @return object 缓存操作对象
*/
private static function cache()
{
if (! isset(self::$_cache))
{
self::$_cache = Util_Cache::factory(self::$_options);
}
return self::$_cache;
}
/**
* 键名加密处理
*
* @param string $key (键名)
* @return string
*/
private static function encryptKey($key)
{
return md5(self::$_key . md5($key));
}
/**
* 设置
*
* @param string $key (键名)
* @param source $data (数据)
* @param integer $expire (有效期 默认为1天)
* @return void
*/
public static function set($key, $data, $expire = 86400)
{
self::cache()->set(self::encryptKey($key), $data, $expire);
}
/**
* 获取
*
* @param string $key (键名)
* @return source
*/
public static function get($key)
{
return self::cache()->get(self::encryptKey($key));
}
/**
* 清除
*
* @param string $key (键名)
* @param integer $delay (延时时间,单位秒)
* @return array | boolean
* @since 0.4
*/
public static function del($key, $delay = 0)
{
return self::cache()->del(self::encryptKey($key), $delay);
}
}