| 1 |
<?php |
| 2 |
/** |
| 3 |
* Cache.php |
| 4 |
* |
| 5 |
* The Cache class file. |
| 6 |
* |
| 7 |
* PHP versions 5 |
| 8 |
* |
| 9 |
* @author Alexander Schneider <alexanderschneider85@gmail.com> |
| 10 |
* @copyright 2008-2017 Alexander Schneider |
| 11 |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 |
| 12 |
* @version SVN: $id$ |
| 13 |
* @link http://wordpress.org/extend/plugins/user-access-manager/ |
| 14 |
*/ |
| 15 |
namespace UserAccessManager\Cache; |
| 16 |
|
| 17 |
/** |
| 18 |
* Class Cache |
| 19 |
* |
| 20 |
* @package UserAccessManager\Cache |
| 21 |
*/ |
| 22 |
class Cache |
| 23 |
{ |
| 24 |
/** |
| 25 |
* @var array |
| 26 |
*/ |
| 27 |
private $cache = []; |
| 28 |
|
| 29 |
/** |
| 30 |
* Returns a generated cache key. |
| 31 |
* |
| 32 |
* @return string |
| 33 |
*/ |
| 34 |
public function generateCacheKey() |
| 35 |
{ |
| 36 |
$arguments = func_get_args(); |
| 37 |
|
| 38 |
return implode('|', $arguments); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Adds the variable to the cache. |
| 43 |
* |
| 44 |
* @param string $key The cache key |
| 45 |
* @param mixed $value The value. |
| 46 |
*/ |
| 47 |
public function addToCache($key, $value) |
| 48 |
{ |
| 49 |
$this->cache[$key] = $value; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Returns a value from the cache by the given key. |
| 54 |
* |
| 55 |
* @param string $key |
| 56 |
* |
| 57 |
* @return mixed |
| 58 |
*/ |
| 59 |
public function getFromCache($key) |
| 60 |
{ |
| 61 |
if (isset($this->cache[$key]) === true) { |
| 62 |
return $this->cache[$key]; |
| 63 |
} |
| 64 |
|
| 65 |
return null; |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Flushes the cache. |
| 70 |
*/ |
| 71 |
public function flushCache() |
| 72 |
{ |
| 73 |
$this->cache = []; |
| 74 |
} |
| 75 |
} |
| 76 |
|