8000 Merge branch '4.4' into 5.3 · symfony/cache@2056f21 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2056f21

Browse files
committed
Merge branch '4.4' into 5.3
* 4.4: added missing translations for Bosnian (bs) Add the missing greek translations for security core and validator component Do not call substr_count() if ip is null to avoid deprecation warning in PHP 8.1 [Security][Validator] Add missing translations for Slovenian (sl) [Security][Validator] Add missing translations for Finnish (fi) [Cache] Commit items implicitly only when deferred keys are requested [HttpClient] fix missing kernel.reset tag on TraceableHttpClient services
2 parents ba581a0 + 8810b1a commit 2056f21

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

Adapter/TagAwareAdapter.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,10 @@ public function invalidateTags(array $tags)
157157
*/
158158
public function hasItem($key)
159159
{
160-
if ($this->deferred) {
160+
if (\is_string($key) && isset($this->deferred[$key])) {
161161
$this->commit();
162162
}
163+
163164
if (!$this->pool->hasItem($key)) {
164165
return false;
165166
}
@@ -200,18 +201,21 @@ public function getItem($key)
200201
*/
201202
public function getItems(array $keys = [])
202203
{
203-
if ($this->deferred) {
204-
$this->commit();
205-
}
206204
$tagKeys = [];
205+
$commit = false;
207206

208207
foreach ($keys as $key) {
209208
if ('' !== $key && \is_string($key)) {
209+
$commit = $commit || isset($this->deferred[$key]);
210210
$key = static::TAGS_PREFIX.$key;
211211
$tagKeys[$key] = $key;
212212
}
213213
}
214214

215+
if ($commit) {
216+
$this->commit();
217+
}
218+
215219
try {
216220
$items = $this->pool->getItems($tagKeys + $keys);
217221
} catch (InvalidArgumentException $e) {

Traits/AbstractAdapterTrait.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,11 @@ public function deleteItems(array $keys)
208208
*/
209209
public function getItem($key)
210210
{
211-
if ($this->deferred) {
211+
$id = $this->getId($key);
212+
213+
if (isset($this->deferred[$key])) {
212214
$this->commit();
213215
}
214-
$id = $this->getId($key);
215216

216217
$isHit = false;
217218
$value = null;
@@ -234,14 +235,18 @@ public function getItem($key)
234235
*/
235236
public function getItems(array $keys = [])
236237
{
237-
if ($this->deferred) {
238-
$this->commit();
239-
}
240238
$ids = [];
239+
$commit = false;
241240

242241
foreach ($keys as $key) {
243242
$ids[] = $this->getId($key);
243+
$commit = $commit || isset($this->deferred[$key]);
244+
}
245+
246+
if ($commit) {
247+
$this->commit();
244248
}
249+
245250
try {
246251
$items = $this->doFetch($ids);
247252
} catch (\Exception $e) {

0 commit comments

Comments
 (0)
0