Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a18fd51

Browse filesBrowse files
[Cache] Use generators
1 parent cc84be9 commit a18fd51
Copy full SHA for a18fd51

File tree

2 files changed

+24
-17
lines changed
Filter options

2 files changed

+24
-17
lines changed

‎src/Symfony/Component/Cache/Adapter/AbstractAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
+23-13Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function getItem($key)
114114
$this->commit();
115115
}
116116
if (isset($this->deferred[$key])) {
117-
return $this->deferred[$key];
117+
return clone $this->deferred[$key];
118118
}
119119

120120
$f = $this->createCacheItem;
@@ -138,38 +138,48 @@ public function getItems(array $keys = array())
138138
}
139139
$f = $this->createCacheItem;
140140
$ids = array();
141-
$items = array();
142141

143142
foreach ($keys as $key) {
144143
$id = $this->getId($key);
145144

146145
if (isset($this->deferred[$key])) {
147-
$items[$key] = $this->deferred[$key];
146+
yield $key => clone $this->deferred[$key];
148147
} else {
149-
$ids[$key] = $id;
148+
$ids[$id] = $key;
150149
}
151150
}
152151

153-
$values = $this->doFetch($ids);
154-
155-
foreach ($ids as $key => $id) {
156-
$isHit = isset($values[$id]);
157-
$items[$key] = $f($key, $isHit ? $values[$id] : null, $isHit);
152+
foreach ($this->doFetch(array_keys($ids)) as $id => $value) {
153+
if (isset($ids[$id])) {
154+
yield $ids[$id] => $f($key, $value, true);
155+
unset($ids[$id]);
156+
}
158157
}
159158

160-
return $items;
159+
foreach ($ids as $id => $key) {
160+
yield $key => $f($key, null, false);
161+
}
161162
}
162163

163164
/**
164165
* {@inheritdoc}
165166
*/
166167
public function hasItem($key)
167168
{
168-
if ($this->deferred) {
169-
$this->commit();
169+
$id = $this->getId($key);
170+
171+
if (isset($this->deferred[$key])) {
172+
static $prefix = "\0Symfony\Component\Cache\CacheItem\0";
173+
$item = (array) $this->deferred[$key];
174+
$ok = $this->doSave(array($item[$prefix.'key'] => $item[$prefix.'value']), $item[$prefix.'lifetime']);
175+
unset($this->deferred[$key]);
176+
177+
if (true === $ok || array() === $ok) {
178+
return true;
179+
}
170180
}
171181

172-
return $this->doHave($this->getId($key));
182+
return $this->doHave($id);
173183
}
174184

175185
/**

‎src/Symfony/Component/Cache/Adapter/ProxyAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/ProxyAdapter.php
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,10 @@ public function getItem($key)
5757
public function getItems(array $keys = array())
5858
{
5959
$f = $this->createCacheItem;
60-
$items = array();
6160

6261
foreach ($this->pool->getItems($keys) as $key => $item) {
63-
$items[$key] = $f($key, $item->get(), $item->isHit());
62+
yield $key => $f($key, $item->get(), $item->isHit());
6463
}
65-
66-
return $items;
6764
}
6865

6966
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.