1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Koded package. |
5
|
|
|
* |
6
|
|
|
* (c) Mihail Binev <[email protected]> |
7
|
|
|
* |
8
|
|
|
* Please view the LICENSE distributed with this source code |
9
|
|
|
* for the full copyright and license information. |
10
|
|
|
* |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Koded\Caching\Client; |
14
|
|
|
|
15
|
|
|
use function Koded\Caching\{filter_keys, normalize_ttl}; |
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Trait MultiplesTrait implements all "multi" operations |
19
|
|
|
* separated for easy override in the specific cache classes. |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
trait MultiplesTrait |
23
|
|
|
{ |
24
|
239 |
|
public function getMultiple($keys, $default = null): iterable |
25
|
|
|
{ |
26
|
239 |
|
$filtered = filter_keys($keys, false); |
27
|
|
|
|
28
|
95 |
|
return $this->internalMultiGet($filtered, $default); |
29
|
|
|
} |
30
|
|
|
|
31
|
351 |
|
public function setMultiple($values, $ttl = null): bool |
32
|
|
|
{ |
33
|
351 |
|
$filtered = filter_keys($values, true); |
34
|
207 |
|
$ttl = normalize_ttl($ttl ?? $this->ttl); |
35
|
|
|
|
36
|
127 |
|
if ($ttl !== null && $ttl < 1) { |
37
|
|
|
// All items are considered expired and must be deleted |
38
|
8 |
|
return $this->deleteMultiple(array_keys($filtered)); |
39
|
|
|
} |
40
|
|
|
|
41
|
119 |
|
return $this->internalMultiSet($filtered, $ttl); |
42
|
|
|
} |
43
|
|
|
|
44
|
175 |
|
public function deleteMultiple($keys): bool |
45
|
|
|
{ |
46
|
175 |
|
$filtered = filter_keys($keys, false); |
47
|
|
|
|
48
|
31 |
|
if (empty($filtered)) { |
49
|
8 |
|
return true; |
50
|
|
|
} |
51
|
|
|
|
52
|
31 |
|
return $this->internalMultiDelete($filtered); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/* |
56
|
|
|
* |
57
|
|
|
* Override in specific cache classes. |
58
|
|
|
* |
59
|
|
|
*/ |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param array $keys |
63
|
|
|
* @param mixed $default |
64
|
|
|
* |
65
|
|
|
* @return iterable |
66
|
|
|
*/ |
67
|
83 |
|
private function internalMultiGet(array $keys, $default): iterable |
68
|
|
|
{ |
69
|
83 |
|
$cached = []; |
70
|
83 |
|
foreach ($keys as $key) { |
71
|
83 |
|
$cached[$key] = $this->get($key, $default); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
83 |
|
return $cached; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param array $values |
79
|
|
|
* @param int|null $ttl |
80
|
|
|
* |
81
|
|
|
* @return bool |
82
|
|
|
*/ |
83
|
104 |
|
private function internalMultiSet(array $values, $ttl): bool |
84
|
|
|
{ |
85
|
104 |
|
$cached = 0; |
86
|
104 |
|
foreach ($values as $key => $value) { |
87
|
104 |
|
$this->set($key, $value, $ttl) && ++$cached; |
|
|
|
|
88
|
|
|
} |
89
|
104 |
|
return count($values) === $cached; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param array $keys |
94
|
|
|
* |
95
|
|
|
* @return bool |
96
|
|
|
*/ |
97
|
27 |
|
private function internalMultiDelete(array $keys): bool |
98
|
|
|
{ |
99
|
27 |
|
$deleted = 0; |
100
|
27 |
|
foreach ($keys as $key) { |
101
|
27 |
|
$this->delete($key) && ++$deleted; |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
27 |
|
return count($keys) === $deleted; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths