Skip to content

Commit a7412d3

Browse files
committed
Fixed #855
1 parent ad52a74 commit a7412d3

File tree

7 files changed

+19
-16
lines changed

7 files changed

+19
-16
lines changed

lib/Phpfastcache/Cluster/Drivers/FullReplication/Driver.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ public function getItem(string $key): ExtendedCacheItemInterface
7272
}
7373
}
7474

75-
return $this->getStandardizedItem($item ?? new Item($this, $key, $this->getEventManager()), $this);
75+
if ($item === null) {
76+
$item = new Item($this, $key, $this->getEventManager());
77+
$item->expiresAfter(abs($this->getConfig()->getDefaultTtl()));
78+
}
79+
80+
return $this->getStandardizedItem($item, $this);
7681
}
7782

7883
/**

lib/Phpfastcache/Cluster/Drivers/MasterSlaveReplication/Driver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@
2626
use Phpfastcache\Exceptions\PhpfastcacheDriverException;
2727
use Phpfastcache\Exceptions\PhpfastcacheExceptionInterface;
2828
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
29-
use Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException;
3029
use Phpfastcache\Exceptions\PhpfastcacheIOException;
3130
use Phpfastcache\Exceptions\PhpfastcacheReplicationException;
3231
use Psr\Cache\CacheItemInterface;
33-
use ReflectionException;
3432

3533
class Driver extends ClusterPoolAbstract
3634
{
@@ -61,7 +59,9 @@ public function __construct(string $clusterName, EventManager $em, ExtendedCache
6159
public function getItem(string $key): ExtendedCacheItemInterface
6260
{
6361
return $this->getStandardizedItem(
64-
$this->makeOperation(static fn (ExtendedCacheItemPoolInterface $pool) => $pool->getItem($key)) ?? new Item($this, $key, $this->getEventManager()),
62+
$this->makeOperation(static function (ExtendedCacheItemPoolInterface $pool) use ($key) {
63+
return $pool->getItem($key);
64+
}) ?? (new Item($this, $key, $this->getEventManager()))->expiresAfter(abs($this->getConfig()->getDefaultTtl())),
6565
$this
6666
);
6767
}

lib/Phpfastcache/Cluster/Drivers/RandomReplication/Driver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Driver extends MasterSlaveReplicationDriver
2727
/**
2828
* RandomReplicationCluster constructor.
2929
* @param string $clusterName
30+
* @param EventManagerInterface $em
3031
* @param ExtendedCacheItemPoolInterface ...$driverPools
3132
* @throws ReflectionException
3233
*/

lib/Phpfastcache/Cluster/Drivers/SemiReplication/Driver.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class Driver extends ClusterPoolAbstract
2626
{
2727
/**
2828
* @inheritDoc
29-
* @throws PhpfastcacheReplicationException
3029
* @throws InvalidArgumentException
30+
* @throws PhpfastcacheReplicationException
3131
*/
3232
public function getItem(string $key): ExtendedCacheItemInterface
3333
{
@@ -51,7 +51,12 @@ public function getItem(string $key): ExtendedCacheItemInterface
5151
throw new PhpfastcacheReplicationException('Every pools thrown an exception');
5252
}
5353

54-
return $this->getStandardizedItem($item ?? new Item($this, $key, $this->getEventManager()), $this);
54+
if ($item === null) {
55+
$item = new Item($this, $key, $this->getEventManager());
56+
$item->expiresAfter(abs($this->getConfig()->getDefaultTtl()));
57+
}
58+
59+
return $this->getStandardizedItem($item, $this);
5560
}
5661

5762
/**

lib/Phpfastcache/Core/Pool/CacheItemPoolTrait.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,13 @@
2020
use Phpfastcache\Entities\DriverIO;
2121
use Phpfastcache\Entities\ItemBatch;
2222
use Phpfastcache\Event\Event;
23-
use Phpfastcache\Event\EventManagerDispatcherTrait;
2423
use Phpfastcache\Event\EventReferenceParameter;
2524
use Phpfastcache\Exceptions\PhpfastcacheCoreException;
2625
use Phpfastcache\Exceptions\PhpfastcacheDriverException;
2726
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
2827
use Phpfastcache\Exceptions\PhpfastcacheIOException;
2928
use Phpfastcache\Exceptions\PhpfastcacheLogicException;
30-
use Phpfastcache\Util\ClassNamespaceResolverTrait;
3129
use Psr\Cache\CacheItemInterface;
32-
use ReflectionClass;
33-
use ReflectionObject;
3430
use RuntimeException;
3531

3632
trait CacheItemPoolTrait
@@ -233,7 +229,7 @@ public function getItem(string $key): ExtendedCacheItemInterface
233229

234230
return $item;
235231
}
236-
throw new PhpfastcacheInvalidArgumentException(\sprintf('Item %s was not build due to an unknown error', \gettype($key)));
232+
throw new PhpfastcacheInvalidArgumentException(\sprintf('Item %s was not built due to an unknown error', \gettype($key)));
237233
}
238234

239235
/**

lib/Phpfastcache/Drivers/Redis/Driver.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,7 @@ protected function driverDelete(ExtendedCacheItemInterface $item): bool
161161
{
162162
$this->assertCacheItemType($item, Item::class);
163163

164-
$this->instance->del($item->getKey());
165-
166-
// Redis sometime returns erroneous results
167-
return true;
164+
return (bool) $this->instance->del($item->getKey());
168165
}
169166

170167
/**

tests/ClusterFullReplication.test.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
$clusterAggregator->aggregateDriver(CacheManager::getInstance('Files'));
2929
$clusterAggregator->aggregateDriver(CacheManager::getInstance('Sqlite'));
3030
$cluster = $clusterAggregator->getCluster(AggregatorInterface::STRATEGY_FULL_REPLICATION);
31-
$cluster->clear();
3231

3332
$testHelper->runCRUDTests($cluster);
3433

0 commit comments

Comments
 (0)