| @@ 12-148 (lines=137) @@ | ||
| 9 | * |
|
| 10 | * @package voku\cache |
|
| 11 | */ |
|
| 12 | class AdapterApc implements iAdapter |
|
| 13 | { |
|
| 14 | ||
| 15 | /** |
|
| 16 | * @var bool |
|
| 17 | */ |
|
| 18 | public $installed = false; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * @var bool |
|
| 22 | */ |
|
| 23 | public $debug = false; |
|
| 24 | ||
| 25 | /** |
|
| 26 | * __construct() |
|
| 27 | */ |
|
| 28 | public function __construct() |
|
| 29 | { |
|
| 30 | if ( |
|
| 31 | function_exists('apc_store') === true |
|
| 32 | && |
|
| 33 | ini_get('apc.enabled') |
|
| 34 | ) { |
|
| 35 | $this->installed = true; |
|
| 36 | } |
|
| 37 | } |
|
| 38 | ||
| 39 | /** |
|
| 40 | * Check if apc-cache exists. |
|
| 41 | * |
|
| 42 | * WARNING: use $this->exists($key) instead |
|
| 43 | * |
|
| 44 | * @param string $key |
|
| 45 | * |
|
| 46 | * @return bool |
|
| 47 | * |
|
| 48 | * @internal |
|
| 49 | */ |
|
| 50 | public function apc_cache_exists($key) |
|
| 51 | { |
|
| 52 | return (bool)apc_fetch($key); |
|
| 53 | } |
|
| 54 | ||
| 55 | /** |
|
| 56 | * Clears the APC cache by type. |
|
| 57 | * |
|
| 58 | * @param string $type - If $type is "user", the user cache will be cleared; otherwise, |
|
| 59 | * the system cache (cached files) will be cleared. |
|
| 60 | * |
|
| 61 | * @return boolean |
|
| 62 | * |
|
| 63 | * @internal |
|
| 64 | */ |
|
| 65 | public function cacheClear($type) |
|
| 66 | { |
|
| 67 | return apc_clear_cache($type); |
|
| 68 | } |
|
| 69 | ||
| 70 | /** |
|
| 71 | * Retrieves cached information from APC's data store |
|
| 72 | * |
|
| 73 | * @param string $type - If $type is "user", information about the user cache will be returned. |
|
| 74 | * @param boolean $limited - If $limited is TRUE, the return value will exclude the individual list of cache entries. |
|
| 75 | * This is useful when trying to optimize calls for statistics gathering. |
|
| 76 | * |
|
| 77 | * @return array of cached data (and meta-data) or FALSE on failure. |
|
| 78 | */ |
|
| 79 | public function cacheInfo($type = '', $limited = false) |
|
| 80 | { |
|
| 81 | return apc_cache_info($type, $limited); |
|
| 82 | } |
|
| 83 | ||
| 84 | /** |
|
| 85 | * @inheritdoc |
|
| 86 | */ |
|
| 87 | public function exists($key) |
|
| 88 | { |
|
| 89 | if (function_exists('apc_exists')) { |
|
| 90 | return apc_exists($key); |
|
| 91 | } else { |
|
| 92 | return $this->apc_cache_exists($key); |
|
| 93 | } |
|
| 94 | } |
|
| 95 | ||
| 96 | /** |
|
| 97 | * @inheritdoc |
|
| 98 | */ |
|
| 99 | public function get($key) |
|
| 100 | { |
|
| 101 | if ($this->exists($key)) { |
|
| 102 | return apc_fetch($key); |
|
| 103 | } else { |
|
| 104 | return false; |
|
| 105 | } |
|
| 106 | } |
|
| 107 | ||
| 108 | /** |
|
| 109 | * @inheritdoc |
|
| 110 | */ |
|
| 111 | public function installed() |
|
| 112 | { |
|
| 113 | return $this->installed; |
|
| 114 | } |
|
| 115 | ||
| 116 | /** |
|
| 117 | * @inheritdoc |
|
| 118 | */ |
|
| 119 | public function remove($key) |
|
| 120 | { |
|
| 121 | return apc_delete($key); |
|
| 122 | } |
|
| 123 | ||
| 124 | /** |
|
| 125 | * @inheritdoc |
|
| 126 | */ |
|
| 127 | public function removeAll() |
|
| 128 | { |
|
| 129 | return $this->cacheClear('system') && $this->cacheClear('user'); |
|
| 130 | } |
|
| 131 | ||
| 132 | /** |
|
| 133 | * @inheritdoc |
|
| 134 | */ |
|
| 135 | public function set($key, $value) |
|
| 136 | { |
|
| 137 | return apc_store($key, $value); |
|
| 138 | } |
|
| 139 | ||
| 140 | /** |
|
| 141 | * @inheritdoc |
|
| 142 | */ |
|
| 143 | public function setExpired($key, $data, $ttl) |
|
| 144 | { |
|
| 145 | return apc_store($key, $data, $ttl); |
|
| 146 | } |
|
| 147 | ||
| 148 | } |
|
| 149 | ||
| @@ 12-147 (lines=136) @@ | ||
| 9 | * |
|
| 10 | * @package voku\cache |
|
| 11 | */ |
|
| 12 | class AdapterApcu implements iAdapter |
|
| 13 | { |
|
| 14 | ||
| 15 | /** |
|
| 16 | * @var bool |
|
| 17 | */ |
|
| 18 | public $installed = false; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * @var bool |
|
| 22 | */ |
|
| 23 | public $debug = false; |
|
| 24 | ||
| 25 | /** |
|
| 26 | * __construct() |
|
| 27 | */ |
|
| 28 | public function __construct() |
|
| 29 | { |
|
| 30 | if ( |
|
| 31 | function_exists('apcu_store') === true |
|
| 32 | && |
|
| 33 | ini_get('apc.enabled') |
|
| 34 | ) { |
|
| 35 | $this->installed = true; |
|
| 36 | } |
|
| 37 | } |
|
| 38 | ||
| 39 | /** |
|
| 40 | * Check if apcu-cache exists. |
|
| 41 | * |
|
| 42 | * WARNING: use $this->exists($key) instead |
|
| 43 | * |
|
| 44 | * @param string $key |
|
| 45 | * |
|
| 46 | * @return bool |
|
| 47 | * |
|
| 48 | * @internal |
|
| 49 | */ |
|
| 50 | public function apcu_cache_exists($key) |
|
| 51 | { |
|
| 52 | return (bool)apcu_fetch($key); |
|
| 53 | } |
|
| 54 | ||
| 55 | /** |
|
| 56 | * Clears the APCu cache by type. |
|
| 57 | * |
|
| 58 | * @param string $type - If $type is "user", the user cache will be cleared; otherwise, |
|
| 59 | * the system cache (cached files) will be cleared. |
|
| 60 | * |
|
| 61 | * @return boolean |
|
| 62 | * |
|
| 63 | * @internal |
|
| 64 | */ |
|
| 65 | public function cacheClear($type) |
|
| 66 | { |
|
| 67 | return apcu_clear_cache($type); |
|
| 68 | } |
|
| 69 | ||
| 70 | /** |
|
| 71 | * Retrieves cached information from APCu's data store |
|
| 72 | * |
|
| 73 | * @param boolean $limited - If $limited is TRUE, the return value will exclude the individual list of cache entries. |
|
| 74 | * This is useful when trying to optimize calls for statistics gathering. |
|
| 75 | * |
|
| 76 | * @return array of cached data (and meta-data) or FALSE on failure. |
|
| 77 | */ |
|
| 78 | public function cacheInfo($limited = false) |
|
| 79 | { |
|
| 80 | return apcu_cache_info($limited); |
|
| 81 | } |
|
| 82 | ||
| 83 | /** |
|
| 84 | * @inheritdoc |
|
| 85 | */ |
|
| 86 | public function exists($key) |
|
| 87 | { |
|
| 88 | if (function_exists('apcu_exists')) { |
|
| 89 | return apcu_exists($key); |
|
| 90 | } else { |
|
| 91 | return $this->apcu_cache_exists($key); |
|
| 92 | } |
|
| 93 | } |
|
| 94 | ||
| 95 | /** |
|
| 96 | * @inheritdoc |
|
| 97 | */ |
|
| 98 | public function get($key) |
|
| 99 | { |
|
| 100 | if ($this->exists($key)) { |
|
| 101 | return apc_fetch($key); |
|
| 102 | } else { |
|
| 103 | return false; |
|
| 104 | } |
|
| 105 | } |
|
| 106 | ||
| 107 | /** |
|
| 108 | * @inheritdoc |
|
| 109 | */ |
|
| 110 | public function installed() |
|
| 111 | { |
|
| 112 | return $this->installed; |
|
| 113 | } |
|
| 114 | ||
| 115 | /** |
|
| 116 | * @inheritdoc |
|
| 117 | */ |
|
| 118 | public function remove($key) |
|
| 119 | { |
|
| 120 | return apcu_delete($key); |
|
| 121 | } |
|
| 122 | ||
| 123 | /** |
|
| 124 | * @inheritdoc |
|
| 125 | */ |
|
| 126 | public function removeAll() |
|
| 127 | { |
|
| 128 | return $this->cacheClear('system') && $this->cacheClear('user'); |
|
| 129 | } |
|
| 130 | ||
| 131 | /** |
|
| 132 | * @inheritdoc |
|
| 133 | */ |
|
| 134 | public function set($key, $value) |
|
| 135 | { |
|
| 136 | return apcu_store($key, $value); |
|
| 137 | } |
|
| 138 | ||
| 139 | /** |
|
| 140 | * @inheritdoc |
|
| 141 | */ |
|
| 142 | public function setExpired($key, $data, $ttl) |
|
| 143 | { |
|
| 144 | return apcu_store($key, $data, $ttl); |
|
| 145 | } |
|
| 146 | ||
| 147 | } |
|
| 148 | ||