Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| common_cache_PsrWrapperCache | |
0.00% |
0 / 14 |
|
0.00% |
0 / 6 |
132 | |
0.00% |
0 / 1 |
| 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 | |||
| getPsrSimpleCache | |
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) 2020 (original work) Open Assessment Technologies SA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | use oat\oatbox\service\ConfigurableService; |
| 23 | use Psr\SimpleCache\CacheInterface; |
| 24 | use oat\oatbox\cache\SimpleCache; |
| 25 | |
| 26 | /** |
| 27 | * Wrap the PSR simple cache implementation into the legacy interface |
| 28 | * @deprecated Please use oat\oatbox\cache\SimpleCache |
| 29 | */ |
| 30 | class common_cache_PsrWrapperCache extends ConfigurableService implements common_cache_Cache |
| 31 | { |
| 32 | /** |
| 33 | * puts "something" into the cache, |
| 34 | * * If this is an object and implements Serializable, |
| 35 | * * we use the serial provided by the object |
| 36 | * * else a serial must be provided |
| 37 | * @access public |
| 38 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 39 | * @param mixed $mixed |
| 40 | * @param null $serial |
| 41 | * @param null $ttl |
| 42 | * @return bool |
| 43 | * @throws common_exception_Error |
| 44 | */ |
| 45 | public function put($mixed, $serial = null, $ttl = null) |
| 46 | { |
| 47 | if ($mixed instanceof common_Serializable) { |
| 48 | if (!is_null($serial) && $serial != $mixed->getSerial()) { |
| 49 | throw new common_exception_Error('Serial mismatch for Serializable ' . $mixed->getSerial()); |
| 50 | } |
| 51 | $serial = $mixed->getSerial(); |
| 52 | } |
| 53 | |
| 54 | return $this->getPsrSimpleCache()->set($serial, $mixed, $ttl); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * gets the entry associted to the serial |
| 59 | * |
| 60 | * @access public |
| 61 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 62 | * @param string serial |
| 63 | * @return common_Serializable |
| 64 | * @throws common_cache_NotFoundException |
| 65 | */ |
| 66 | public function get($serial) |
| 67 | { |
| 68 | $returnValue = $this->getPsrSimpleCache()->get($serial, false); |
| 69 | if ($returnValue === false && !$this->getPsrSimpleCache()->has($serial)) { |
| 70 | $msg = "No cache entry found for '" . $serial . "'."; |
| 71 | throw new common_cache_NotFoundException($msg); |
| 72 | } |
| 73 | return $returnValue; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * test whenever an entry associated to the serial exists |
| 78 | * |
| 79 | * @access public |
| 80 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 81 | * @param string serial |
| 82 | * @return boolean |
| 83 | */ |
| 84 | public function has($serial) |
| 85 | { |
| 86 | return $this->getPsrSimpleCache()->has($serial); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * removes an entry from the cache |
| 91 | * |
| 92 | * @access public |
| 93 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 94 | * @param string serial |
| 95 | * @return mixed |
| 96 | */ |
| 97 | public function remove($serial) |
| 98 | { |
| 99 | return $this->getPsrSimpleCache()->delete($serial); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * empties the cache |
| 104 | * |
| 105 | * @access public |
| 106 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 107 | * @return mixed |
| 108 | */ |
| 109 | public function purge() |
| 110 | { |
| 111 | return $this->getPsrSimpleCache()->clear(); |
| 112 | } |
| 113 | |
| 114 | protected function getPsrSimpleCache(): CacheInterface |
| 115 | { |
| 116 | return $this->getServiceLocator()->get(SimpleCache::SERVICE_ID); |
| 117 | } |
| 118 | } |