-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
-
The Used Symfony-Cache-Version is 5.4.45. I have a ChainAdapter wit a default lifetime of 86400:
chain_cache:
default_lifetime: 86400
adapters:
- cache.adapter.apcu
- cache.adapter.redis
When i save an cacheItem with a special ttl there is no problem. But when I have a second VM without an value in the apcu, the chainAdapter will get the value from Redis and then save it to the chain Adapter. The Problem ist that in this case there won't be used the ttl, nore the default lifetime. Here an example to reproduce:
public function test( ChainAdapter $cache ) {
$cacheKey = 'chainTest';
$cacheItem = $cache->getItem($cacheKey);
$cacheItem->set('myValue');
$cacheItem->expiresAfter(60);
$cache->save($cacheItem);
foreach (apcu_cache_info()['cache_list'] as $item) {
if (str_contains($item['info'], $cacheKey)) {
dump($item);
}
}
apcu_clear_cache();
$cacheItem = $cache->getItem($cacheKey);
foreach (apcu_cache_info()['cache_list'] as $item) {
if (str_contains($item['info'], $cacheKey)) {
dump($item);
}
}
}
The ttl of the apcu Cache-Entry ist 60 in the first dump and 86400 in the second one.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
I think, this is a bug. I wrote a Test and it failed in the last line. Should i post this in issues?
use PHPUnit\Framework\TestCase;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\ChainAdapter;
class ChainAdapterTest extends TestCase
{
public function testCachesExpirationAfterGet()
{
$adapter1 = new ArrayAdapter(20);
$adapter2 = new ArrayAdapter(30);
$cache = new ChainAdapter([$adapter1, $adapter2], 40);
$testItemKey = "key";
$cache->save($cache->getItem($testItemKey)->set('value')->expiresAfter(2));
$this->assertTrue($adapter1->hasItem($testItemKey));
$this->assertTrue($adapter2->hasItem($testItemKey));
$adapter1->clear();
$this->assertFalse($adapter1->hasItem($testItemKey));
$this->assertTrue($adapter2->hasItem($testItemKey));
$cache->getItem($testItemKey)->get();
$this->assertTrue($adapter1->hasItem('key'));
$this->assertTrue($adapter2->hasItem('key'));
sleep(3);
$this->assertFalse($adapter2->hasItem('key'));
$this->assertFalse($adapter1->hasItem('key'));
}
}
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment