Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| common_cache_KeyValueCache | |
0.00% |
0 / 19 |
|
0.00% |
0 / 6 |
156 | |
0.00% |
0 / 1 |
| getPersistence | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| put | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
20 | |||
| get | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| has | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| remove | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| purge | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg |
| 19 | * (under the project TAO & TAO2); |
| 20 | * 2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung |
| 21 | * (under the project TAO-TRANSFER); |
| 22 | * 2010-2012 (update and modification) Public Research Centre Henri Tudor |
| 23 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | use oat\oatbox\service\ConfigurableService; |
| 28 | |
| 29 | /** |
| 30 | * Caches data in a key-value store |
| 31 | * |
| 32 | * @access public |
| 33 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 34 | * @package generis |
| 35 | * @deprecated Please use oat\oatbox\cache\SimpleCache |
| 36 | */ |
| 37 | class common_cache_KeyValueCache extends ConfigurableService implements common_cache_Cache |
| 38 | { |
| 39 | public const OPTION_PERSISTENCE = 'persistence'; |
| 40 | |
| 41 | |
| 42 | /** |
| 43 | * @var common_persistence_KeyValuePersistence |
| 44 | */ |
| 45 | private $persistence; |
| 46 | |
| 47 | protected function getPersistence() |
| 48 | { |
| 49 | if (is_null($this->persistence)) { |
| 50 | $this->persistence = $this |
| 51 | ->getServiceLocator() |
| 52 | ->get('generis/persistences') |
| 53 | ->getPersistenceById($this->getOption(self::OPTION_PERSISTENCE)); |
| 54 | } |
| 55 | return $this->persistence; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * puts "something" into the cache, |
| 60 | * * If this is an object and implements Serializable, |
| 61 | * * we use the serial provided by the object |
| 62 | * * else a serial must be provided |
| 63 | * @access public |
| 64 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 65 | * @param mixed $mixed |
| 66 | * @param null $serial |
| 67 | * @param null $ttl |
| 68 | * @return bool |
| 69 | * @throws common_exception_Error |
| 70 | */ |
| 71 | public function put($mixed, $serial = null, $ttl = null) |
| 72 | { |
| 73 | if ($mixed instanceof common_Serializable) { |
| 74 | if (!is_null($serial) && $serial != $mixed->getSerial()) { |
| 75 | throw new common_exception_Error('Serial mismatch for Serializable ' . $mixed->getSerial()); |
| 76 | } |
| 77 | $serial = $mixed->getSerial(); |
| 78 | } |
| 79 | |
| 80 | return $this->getPersistence()->set($serial, $mixed, $ttl); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * gets the entry associted to the serial |
| 85 | * |
| 86 | * @access public |
| 87 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 88 | * @param string serial |
| 89 | * @return common_Serializable |
| 90 | * @throws common_cache_NotFoundException |
| 91 | */ |
| 92 | public function get($serial) |
| 93 | { |
| 94 | $returnValue = $this->getPersistence()->get($serial); |
| 95 | if ($returnValue === false && !$this->has($serial)) { |
| 96 | $msg = "No cache entry found for '" . $serial . "'."; |
| 97 | throw new common_cache_NotFoundException($msg); |
| 98 | } |
| 99 | return $returnValue; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * test whenever an entry associated to the serial exists |
| 104 | * |
| 105 | * @access public |
| 106 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 107 | * @param string serial |
| 108 | * @return boolean |
| 109 | */ |
| 110 | public function has($serial) |
| 111 | { |
| 112 | return $this->getPersistence()->exists($serial); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * removes an entry from the cache |
| 117 | * |
| 118 | * @access public |
| 119 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 120 | * @param string serial |
| 121 | * @return mixed |
| 122 | */ |
| 123 | public function remove($serial) |
| 124 | { |
| 125 | return $this->getPersistence()->del($serial); |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * empties the cache |
| 130 | * |
| 131 | * @access public |
| 132 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 133 | * @return mixed |
| 134 | */ |
| 135 | public function purge() |
| 136 | { |
| 137 | return $this->getPersistence()->purge(); |
| 138 | } |
| 139 | } |