Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit8f8af9c

Browse files
committed
[Cache] Fix saving items with no expiration through ProxyAdapter
1 parentee211c4 commit8f8af9c

File tree

5 files changed

+74
-10
lines changed

5 files changed

+74
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static function ($deferred, $namespace, &$expiredIds) use ($getId, $defaultLifet
7474
$key = (string)$key;
7575
if (null ===$item->expiry) {
7676
$ttl =0 <$defaultLifetime ?$defaultLifetime :0;
77-
}elseif (0 ===$item->expiry) {
77+
}elseif (!$item->expiry) {
7878
$ttl =0;
7979
}elseif (0 >=$ttl = (int) (0.1 +$item->expiry -$now)) {
8080
$expiredIds[] =$getId($key);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static function ($deferred, &$expiredIds) use ($getId, $tagPrefix, $defaultLifet
8080
$key = (string)$key;
8181
if (null ===$item->expiry) {
8282
$ttl =0 <$defaultLifetime ?$defaultLifetime :0;
83-
}elseif (0 ===$item->expiry) {
83+
}elseif (!$item->expiry) {
8484
$ttl =0;
8585
}elseif (0 >=$ttl = (int) (0.1 +$item->expiry -$now)) {
8686
$expiredIds[] =$getId($key);

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ public function save(CacheItemInterface $item)
124124
$value =$item["\0*\0value"];
125125
$expiry =$item["\0*\0expiry"];
126126

127-
if (0 ===$expiry) {
128-
$expiry = \PHP_INT_MAX;
129-
}
130-
131-
if (null !==$expiry &&$expiry <=microtime(true)) {
132-
$this->deleteItem($key);
127+
if (null !==$expiry) {
128+
if (!$expiry) {
129+
$expiry = \PHP_INT_MAX;
130+
}elseif ($expiry <=microtime(true)) {
131+
$this->deleteItem($key);
133132

134-
returntrue;
133+
returntrue;
134+
}
135135
}
136136
if ($this->storeSerialized &&null ===$value =$this->freeze($value,$key)) {
137137
returnfalse;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static function (CacheItemInterface $innerItem, array $item) {
8888
$item["\0*\0value"] = ["\x9D".pack('VN', (int) (0.1 +$metadata[self::METADATA_EXPIRY] -self::METADATA_EXPIRY_OFFSET),$metadata[self::METADATA_CTIME])."\x5F" =>$item["\0*\0value"]];
8989
}
9090
$innerItem->set($item["\0*\0value"]);
91-
$innerItem->expiresAt(null !==$item["\0*\0expiry"] ? \DateTime::createFromFormat('U.u',sprintf('%.6F',0 ===$item["\0*\0expiry"] ? \PHP_INT_MAX :$item["\0*\0expiry"])) :null);
91+
$innerItem->expiresAt(null !==$item["\0*\0expiry"] ? \DateTime::createFromFormat('U.u',sprintf('%.6F',$item["\0*\0expiry"])) :null);
9292
},
9393
null,
9494
CacheItem::class
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
4+
namespaceSymfony\Component\Cache\Tests\Adapter;
5+
6+
usePsr\Cache\CacheItemPoolInterface;
7+
useSymfony\Component\Cache\Adapter\AbstractAdapter;
8+
useSymfony\Component\Cache\Adapter\ProxyAdapter;
9+
useSymfony\Component\Cache\Adapter\RedisAdapter;
10+
useSymfony\Component\Cache\CacheItem;
11+
12+
/**
13+
* @group integration
14+
*/
15+
class ProxyAdapterAndRedisAdapterTestextends AbstractRedisAdapterTest
16+
{
17+
protected$skippedTests = [
18+
'testPrune' =>'RedisAdapter does not implement PruneableInterface.',
19+
];
20+
21+
publicstaticfunctionsetUpBeforeClass():void
22+
{
23+
parent::setUpBeforeClass();
24+
self::$redis = AbstractAdapter::createConnection('redis://'.getenv('REDIS_HOST'));;
25+
}
26+
27+
publicfunctioncreateCachePool($defaultLifetime =0,string$testMethod =null):CacheItemPoolInterface
28+
{
29+
returnnewProxyAdapter(newRedisAdapter(self::$redis,str_replace('\\','.',__CLASS__),100),'ProxyNS',$defaultLifetime);
30+
}
31+
32+
publicfunctiontestSaveItemPermanently()
33+
{
34+
$setCacheItemExpiry = \Closure::bind(
35+
staticfunction (CacheItem$item,$expiry) {
36+
$item->expiry =$expiry;
37+
38+
return$item;
39+
},
40+
null,
41+
CacheItem::class
42+
);
43+
44+
$cache =$this->createCachePool(1);
45+
$value =rand();
46+
$item =$cache->getItem('foo');
47+
$setCacheItemExpiry($item,0);
48+
$cache->save($item->set($value));
49+
$item =$cache->getItem('bar');
50+
$setCacheItemExpiry($item,0.0);
51+
$cache->save($item->set($value));
52+
$item =$cache->getItem('baz');
53+
$cache->save($item->set($value));
54+
55+
$this->assertSame($value,$this->cache->getItem('foo')->get());
56+
$this->assertSame($value,$this->cache->getItem('bar')->get());
57+
$this->assertSame($value,$this->cache->getItem('baz')->get());
58+
59+
sleep(1);
60+
$this->assertSame($value,$this->cache->getItem('foo')->get());
61+
$this->assertSame($value,$this->cache->getItem('bar')->get());
62+
$this->assertFalse($this->cache->getItem('baz')->isHit());
63+
}
64+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp