Skip to content

Commit daaada2

Browse files
committed
Fixed wrong itemInstance behaviour
1 parent b995b28 commit daaada2

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/phpFastCache/Core/StandardPsr6StructureTrait.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,13 @@ public function hasItem($key)
120120
*/
121121
public function clear()
122122
{
123-
return $this->driverClear();
123+
if ($this->driverClear()) {
124+
$this->itemInstances = [];
125+
126+
return true;
127+
}
128+
129+
return false;
124130
}
125131

126132
/**
@@ -130,8 +136,10 @@ public function clear()
130136
*/
131137
public function deleteItem($key)
132138
{
133-
if ($this->hasItem($key)) {
134-
return $this->driverDelete($this->getItem($key));
139+
if ($this->hasItem($key) && $this->driverDelete($this->getItem($key))) {
140+
unset($this->itemInstances[ $key ]);
141+
142+
return true;
135143
}
136144

137145
return false;
@@ -162,6 +170,10 @@ public function deleteItems(array $keys)
162170
*/
163171
public function save(CacheItemInterface $item)
164172
{
173+
if (!array_key_exists($item->getKey(), $this->itemInstances)) {
174+
$this->itemInstances[ $item->getKey() ] = $item;
175+
}
176+
165177
return $this->driverWrite($item) && $this->driverWriteTags($item);
166178
}
167179

@@ -171,6 +183,10 @@ public function save(CacheItemInterface $item)
171183
*/
172184
public function saveDeferred(CacheItemInterface $item)
173185
{
186+
if (!array_key_exists($item->getKey(), $this->itemInstances)) {
187+
$this->itemInstances[ $item->getKey() ] = $item;
188+
}
189+
174190
return $this->deferredList[ $item->getKey() ] = $item;
175191
}
176192

0 commit comments

Comments
 (0)