1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved. |
---|
6 | * |
---|
7 | * http://www.lockon.co.jp/ |
---|
8 | * |
---|
9 | * This program is free software; you can redistribute it and/or |
---|
10 | * modify it under the terms of the GNU General Public License |
---|
11 | * as published by the Free Software Foundation; either version 2 |
---|
12 | * of the License, or (at your option) any later version. |
---|
13 | * |
---|
14 | * This program is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with this program; if not, write to the Free Software |
---|
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | require DATA_REALDIR . 'module/Cache/Lite.php'; |
---|
25 | |
---|
26 | /** |
---|
27 | * Cache controll using PEAR::Cache_Lite. |
---|
28 | */ |
---|
29 | class SC_Cache |
---|
30 | { |
---|
31 | |
---|
32 | /** |
---|
33 | * Instance of PEAR::Cache_Lite class. |
---|
34 | * @var object |
---|
35 | */ |
---|
36 | static $_instance = NULL; |
---|
37 | |
---|
38 | /** |
---|
39 | * Default cache lifetime. |
---|
40 | */ |
---|
41 | const LIFETIME = MAX_LIFETIME; |
---|
42 | |
---|
43 | /** |
---|
44 | * Directory to save cache files. |
---|
45 | */ |
---|
46 | const CACHEDIR = MASTER_DATA_REALDIR; |
---|
47 | |
---|
48 | /** |
---|
49 | * Create Cache_Lite object and set it to static variable. |
---|
50 | * |
---|
51 | * @return void |
---|
52 | */ |
---|
53 | public static function forge() |
---|
54 | { |
---|
55 | $options = array( |
---|
56 | 'cacheDir' => SC_Cache_Ex::CACHEDIR, |
---|
57 | 'lifeTime' => SC_Cache_Ex::LIFETIME, |
---|
58 | 'automaticSerialization' => TRUE |
---|
59 | ); |
---|
60 | SC_Cache_Ex::$_instance = new Cache_Lite($options); |
---|
61 | } |
---|
62 | |
---|
63 | /** |
---|
64 | * Get Cache_Lite object. |
---|
65 | * |
---|
66 | * @return void |
---|
67 | */ |
---|
68 | public static function getInstance() |
---|
69 | { |
---|
70 | is_null(SC_Cache_Ex::$_instance) and SC_Cache_Ex::forge(); |
---|
71 | return SC_Cache_Ex::$_instance; |
---|
72 | } |
---|
73 | |
---|
74 | /** |
---|
75 | * Get data from cache. |
---|
76 | * |
---|
77 | * @param string $id cache id |
---|
78 | * @param string $group name of the cache group |
---|
79 | * @param int $lifeTime custom lifetime |
---|
80 | * @return mixed data of cache (else : false) |
---|
81 | */ |
---|
82 | public static function get($id, $group = 'default', $lifeTime = NULL) |
---|
83 | { |
---|
84 | $processor = SC_Cache_Ex::getInstance(); |
---|
85 | |
---|
86 | // set custom lifetime. |
---|
87 | !is_null($lifeTime) and $processor->setOption('lifeTime', $lifeTime); |
---|
88 | |
---|
89 | $cache = $processor->get($id, $group); |
---|
90 | |
---|
91 | // set back to default lifetime. |
---|
92 | !is_null($lifeTime) and $processor->setOption('lifeTime', SC_Cache_Ex::$_lifetime); |
---|
93 | |
---|
94 | return $cache; |
---|
95 | } |
---|
96 | |
---|
97 | /** |
---|
98 | * Save data into cache. |
---|
99 | * |
---|
100 | * @param mixed $data data of cache |
---|
101 | * @param string $id cache id |
---|
102 | * @param string $group name of the cache group |
---|
103 | * @return void |
---|
104 | */ |
---|
105 | public static function save($data, $id, $group = 'default') |
---|
106 | { |
---|
107 | $processor = SC_Cache_Ex::getInstance(); |
---|
108 | |
---|
109 | $processor->save($data, $id, $group); |
---|
110 | } |
---|
111 | |
---|
112 | /** |
---|
113 | * Clean cache. |
---|
114 | * |
---|
115 | * @param string $group name of the cache group |
---|
116 | * @return void |
---|
117 | */ |
---|
118 | public static function clean($group = FALSE) |
---|
119 | { |
---|
120 | $processor = SC_Cache_Ex::getInstance(); |
---|
121 | |
---|
122 | $processor->clean($group); |
---|
123 | } |
---|
124 | } |
---|