Cache.php
6 years ago
Capability.php
6 years ago
LoginRedirect.php
6 years ago
LogoutRedirect.php
6 years ago
Menu.php
6 years ago
Metabox.php
6 years ago
Policy.php
6 years ago
Post.php
6 years ago
Redirect.php
6 years ago
Route.php
6 years ago
Toolbar.php
6 years ago
Uri.php
6 years ago
Visibility.php
6 years ago
Cache.php
101 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * ====================================================================== |
| 5 | * LICENSE: This file is subject to the terms and conditions defined in * |
| 6 | * file 'license.txt', which is part of this source code package. * |
| 7 | * ====================================================================== |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * AAM cache object |
| 12 | * |
| 13 | * @package AAM |
| 14 | * @author Vasyl Martyniuk <vasyl@vasyltech.com> |
| 15 | */ |
| 16 | class AAM_Core_Object_Cache extends AAM_Core_Object { |
| 17 | |
| 18 | /** |
| 19 | * Is cache enabled? |
| 20 | * |
| 21 | * @var boolean |
| 22 | * |
| 23 | * @access protected |
| 24 | */ |
| 25 | protected $enabled = true; |
| 26 | |
| 27 | /** |
| 28 | * Constructor |
| 29 | * |
| 30 | * @param AAM_Core_Subject $subject |
| 31 | * |
| 32 | * @return void |
| 33 | * |
| 34 | * @access public |
| 35 | */ |
| 36 | public function __construct(AAM_Core_Subject $subject) { |
| 37 | parent::__construct($subject); |
| 38 | |
| 39 | // Determine if cache is enabled |
| 40 | $status = AAM_Core_Config::get('core.cache.status', 'enabled'); |
| 41 | |
| 42 | if (AAM::isAAM() || ($status !== 'enabled')) { |
| 43 | $this->enabled = false; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * |
| 49 | * @param type $type |
| 50 | * @param type $id |
| 51 | * @param type $value |
| 52 | */ |
| 53 | public function add($type, $id, $value) { |
| 54 | $option = $this->getOption(); |
| 55 | |
| 56 | $limit = AAM_Core_Config::get('core.cache.limit', 1000); |
| 57 | if (isset($option[$type][$id]) && (count($option[$type][$id]) >= $limit)) { |
| 58 | array_shift($option[$type][$id]); |
| 59 | } |
| 60 | |
| 61 | $option[$type][$id] = $value; |
| 62 | $this->setOption($option); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Get cache |
| 67 | * |
| 68 | * @param string $type |
| 69 | * @param string|int $id |
| 70 | * @param mixed $default |
| 71 | * |
| 72 | * @return mixed |
| 73 | * |
| 74 | * @access public |
| 75 | */ |
| 76 | public function get($type, $id = 0, $default = array()) { |
| 77 | $option = $this->getOption(); |
| 78 | |
| 79 | return (isset($option[$type][$id]) ? $option[$type][$id] : $default); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Save cache |
| 84 | * |
| 85 | * @return bool |
| 86 | * |
| 87 | * @access public |
| 88 | */ |
| 89 | public function save() { |
| 90 | return true; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * |
| 95 | * @return type |
| 96 | */ |
| 97 | public function reset() { |
| 98 | return $this->getSubject()->deleteOption('cache'); |
| 99 | } |
| 100 | |
| 101 | } |