Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
MultipleCacheTrait
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
3 / 3
8
100.00% covered (success)
100.00%
1 / 1
 deleteMultiple
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 getMultiple
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 setMultiple
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
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
22namespace oat\oatbox\cache;
23
24/**
25 * Caches data in a key-value store
26 *
27 * @access public
28 * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu>
29 * @package generis
30 */
31trait MultipleCacheTrait
32{
33    public function deleteMultiple($keys)
34    {
35        $success = true;
36        foreach ($keys as $key) {
37            $success = $this->delete($key) && $success;
38        }
39        return $success;
40    }
41
42    public function getMultiple($keys, $default = null)
43    {
44        $values = [];
45        foreach ($keys as $key) {
46            $values[$key] = $this->get($key, $default);
47        }
48        return $values;
49    }
50
51    public function setMultiple($values, $ttl = null)
52    {
53        $success = true;
54        foreach ($values as $key => $value) {
55            $success = $this->set($key, $value, $ttl) && $success;
56        }
57        return $success;
58    }
59}