1: | <?php |
2: | /** |
3: | * Cache engine For XOOPS |
4: | * |
5: | * You may not change or alter any portion of this comment or credits |
6: | * of supporting developers from this source code or any supporting source code |
7: | * which is considered copyrighted (c) material of the original comment or credit authors. |
8: | * This program is distributed in the hope that it will be useful, |
9: | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10: | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11: | * |
12: | * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
13: | * @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html) |
14: | * @package class |
15: | * @subpackage cache |
16: | * @since 2.3.0 |
17: | * @author Taiwen Jiang <phppp@users.sourceforge.net> |
18: | */ |
19: | defined('XOOPS_ROOT_PATH') || exit('Restricted access'); |
20: | |
21: | /** |
22: | * APC storage engine for cache. |
23: | * |
24: | * |
25: | * PHP versions 4 and 5 |
26: | * |
27: | * CakePHP(tm) : Rapid Development Framework <https://www.cakephp.org/> |
28: | * Copyright 2005-2008, Cake Software Foundation, Inc. |
29: | * 1785 E. Sahara Avenue, Suite 490-204 |
30: | * Las Vegas, Nevada 89104 |
31: | * |
32: | * Licensed under The MIT License |
33: | * Redistributions of files must retain the above copyright notice. |
34: | * |
35: | * @filesource |
36: | * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. |
37: | * @link https://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project |
38: | * @package cake |
39: | * @subpackage cake.cake.libs.cache |
40: | * @since CakePHP(tm) v 1.2.0.4933 |
41: | * @modifiedby $LastChangedBy$ |
42: | * @lastmodified $Date$ |
43: | * @license https://www.opensource.org/licenses/mit-license.php The MIT License |
44: | */ |
45: | |
46: | /** |
47: | * APC storage engine for cache |
48: | * |
49: | * @package cake |
50: | * @subpackage cake.cake.libs.cache |
51: | */ |
52: | class XoopsCacheApc extends XoopsCacheEngine |
53: | { |
54: | /** |
55: | * Initialize the Cache Engine |
56: | * |
57: | * Called automatically by the cache frontend |
58: | * To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array()); |
59: | * |
60: | * @param array $settings array of setting for the engine |
61: | * |
62: | * @return boolean True if the engine has been successfully initialized, false if not |
63: | * @see CacheEngine::__defaults |
64: | * @access public |
65: | */ |
66: | public function init($settings = array()) |
67: | { |
68: | parent::init($settings); |
69: | |
70: | return function_exists('apc_cache_info'); |
71: | } |
72: | |
73: | /** |
74: | * Write data for key into cache |
75: | * |
76: | * @param string $key Identifier for the data |
77: | * @param mixed $value Data to be cached |
78: | * @param integer $duration How long to cache the data, in seconds |
79: | * @return bool|array Returns TRUE on success or FALSE on failure | array with error keys. |
80: | * @access public |
81: | */ |
82: | public function write($key, $value, $duration = null) |
83: | { |
84: | return apc_store($key, $value, $duration); |
85: | } |
86: | |
87: | /** |
88: | * Read a key from the cache |
89: | * |
90: | * @param string $key Identifier for the data |
91: | * @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it |
92: | * @access public |
93: | */ |
94: | public function read($key) |
95: | { |
96: | return apc_fetch($key); |
97: | } |
98: | |
99: | /** |
100: | * Delete a key from the cache |
101: | * |
102: | * @param string $key Identifier for the data |
103: | * @return bool|string[] Returns TRUE on success or FALSE on failure. For array of keys returns list of failed keys. |
104: | * @access public |
105: | */ |
106: | public function delete($key) |
107: | { |
108: | return apc_delete($key); |
109: | } |
110: | |
111: | /** |
112: | * Delete all keys from the cache |
113: | * |
114: | * @return boolean True if the cache was successfully cleared, false otherwise |
115: | * @access public |
116: | */ |
117: | public function clear($check = null) |
118: | { |
119: | return apc_clear_cache('user'); |
120: | } |
121: | } |
122: |