File tree

6 files changed

+39
-7
lines changed

6 files changed

+39
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,8 @@ protected function getStandardizedItem(ExtendedCacheItemInterface $item, Extende
162162
if ($driverPool === $this) {
163163
/** @var ExtendedCacheItemInterface $itemPool */
164164
$itemClass = $driverPool->getClassNamespace() . '\\' . 'Item';
165-
$itemPool = new $itemClass($this, $item->getKey());
166-
$itemPool->setEventManager($this->getEventManager())
167-
->set($item->get())
165+
$itemPool = new $itemClass($this, $item->getKey(), $this->getEventManager());
166+
$itemPool->set($item->get())
168167
->setHit($item->isHit())
169168
->setTags($item->getTags())
170169
->expiresAt($item->getExpirationDate())
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ public function getItem($key)
7575
}
7676
}
7777

78-
return $this->getStandardizedItem($item ?? new Item($this, $key), $this);
78+
if ($item === null) {
79+
$item = new Item($this, $key, $this->getEventManager());
80+
$item->expiresAfter(abs($this->getConfig()->getDefaultTtl()));
81+
}
82+
83+
return $this->getStandardizedItem($item, $this);
7984
}
8085

8186
/**
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function getItem($key)
6262
static function (ExtendedCacheItemPoolInterface $pool) use ($key) {
6363
return $pool->getItem($key);
6464
}
65-
) ?? new Item($this, $key),
65+
) ?? (new Item($this, $key, $this->getEventManager()))->expiresAfter(abs($this->getConfig()->getDefaultTtl())),
6666
$this
6767
);
6868
}
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ public function getItem($key)
5454
throw new PhpfastcacheReplicationException('Every pools thrown an exception');
5555
}
5656

57-
return $this->getStandardizedItem($item ?? new Item($this, $key), $this);
57+
if ($item === null) {
58+
$item = new Item($this, $key, $this->getEventManager());
59+
$item->expiresAfter(abs($this->getConfig()->getDefaultTtl()));
60+
}
61+
62+
return $this->getStandardizedItem($item, $this);
5863
}
5964

6065
/**
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use Phpfastcache\Core\Item\{ExtendedCacheItemInterface, ItemBaseTrait};
2020
use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
21+
use Phpfastcache\Event\EventManagerInterface;
2122
use Phpfastcache\Exceptions\{PhpfastcacheInvalidArgumentException};
2223

2324
/**
@@ -30,6 +31,12 @@ abstract class ItemAbstract implements ExtendedCacheItemInterface
3031
ItemBaseTrait::__construct as __BaseConstruct;
3132
}
3233

34+
public function __construct(ExtendedCacheItemPoolInterface $driver, $key, EventManagerInterface $em)
35+
{
36+
$this->setEventManager($em);
37+
$this->__BaseConstruct($driver, $key);
38+
}
39+
3340
/**
3441
* @param ExtendedCacheItemPoolInterface $driver
3542
* @return static
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,12 @@ public function accessInaccessibleMember($obj, $prop)
349349
*/
350350
public function errorHandler(int $errno, string $errstr, string $errfile, int $errline)
351351
{
352-
$errorType = '';
352+
// Silenced errors
353+
if (!(error_reporting() & $errno)){
354+
return;
355+
}
353356

357+
$errorType = '';
354358
switch ($errno) {
355359
case E_PARSE:
356360
case E_ERROR:
@@ -433,6 +437,18 @@ public function runCRUDTests(ExtendedCacheItemPoolInterface $pool, bool $poolCle
433437
$cacheItem = $pool->getItem($cacheKey);
434438
$this->printInfoText('Using cache key: ' . $cacheKey);
435439

440+
/**
441+
* Default TTL - 1sec is for dealing with potential script execution delay
442+
* @see https://.com/PHPSocialNetwork/phpfastcache/issues/855
443+
*/
444+
if($cacheItem->getTtl() < $pool->getConfig()->getDefaultTtl() - 1) {
445+
$this->assertFail(\sprintf(
446+
'The expected TTL of the cache item was ~%ds, got %ds',
447+
$pool->getConfig()->getDefaultTtl(),
448+
$cacheItem->getTtl()
449+
));
450+
}
451+
436452
$cacheItem->set($cacheValue)
437453
->expiresAfter(60)
438454
->addTags([$cacheTag, $cacheTag2]);

0 commit comments

Comments
 (0)