[22587] | 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 | |
---|
[23143] | 24 | require DATA_REALDIR . 'module/Cache/Lite.php'; |
---|
| 25 | |
---|
[22587] | 26 | /** |
---|
| 27 | * Cache controll using PEAR::Cache_Lite. |
---|
| 28 | */ |
---|
| 29 | class SC_Cache |
---|
| 30 | { |
---|
| 31 | /** |
---|
| 32 | * Instance of PEAR::Cache_Lite class. |
---|
[22856] | 33 | * @var object |
---|
[22587] | 34 | */ |
---|
[23126] | 35 | public static $_instance = NULL; |
---|
[22587] | 36 | |
---|
| 37 | /** |
---|
[22856] | 38 | * Default cache lifetime. |
---|
[22587] | 39 | */ |
---|
| 40 | const LIFETIME = MAX_LIFETIME; |
---|
| 41 | |
---|
| 42 | /** |
---|
| 43 | * Directory to save cache files. |
---|
| 44 | */ |
---|
| 45 | const CACHEDIR = MASTER_DATA_REALDIR; |
---|
| 46 | |
---|
| 47 | /** |
---|
| 48 | * Create Cache_Lite object and set it to static variable. |
---|
[22856] | 49 | * |
---|
[22587] | 50 | * @return void |
---|
| 51 | */ |
---|
| 52 | public static function forge() |
---|
| 53 | { |
---|
| 54 | $options = array( |
---|
| 55 | 'cacheDir' => SC_Cache_Ex::CACHEDIR, |
---|
| 56 | 'lifeTime' => SC_Cache_Ex::LIFETIME, |
---|
| 57 | 'automaticSerialization' => TRUE |
---|
| 58 | ); |
---|
| 59 | SC_Cache_Ex::$_instance = new Cache_Lite($options); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | /** |
---|
| 63 | * Get Cache_Lite object. |
---|
| 64 | * |
---|
| 65 | * @return void |
---|
| 66 | */ |
---|
| 67 | public static function getInstance() |
---|
| 68 | { |
---|
| 69 | is_null(SC_Cache_Ex::$_instance) and SC_Cache_Ex::forge(); |
---|
[22856] | 70 | |
---|
[22587] | 71 | return SC_Cache_Ex::$_instance; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | /** |
---|
| 75 | * Get data from cache. |
---|
| 76 | * |
---|
[23126] | 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) |
---|
[22587] | 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 | * |
---|
[23126] | 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 |
---|
[22587] | 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 | * |
---|
[23126] | 115 | * @param string $group name of the cache group |
---|
[22587] | 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 | } |
---|