2016-10-07 2 views
1

캐시 어댑터에서 기본 수명을 구성해야하지만 이상한 일이 발생했습니다. 다음은 작동하지 않습니다! :/캐시 구성 요소의 기본 수명

use Symfony\Component\Cache\Adapter\FilesystemAdapter; 

// in seconds; applied to cache items that don't define their own lifetime 
// 0 means to store the cache items indefinitely (i.e. until the files are deleted) 
$cache = new FilesystemAdapter('my_namespace', 5); // <-- default lifetime 5 seconds 
$latestNews = $cache->getItem('latest_news'); 

if (!$latestNews->isHit()) { 
    $news = ['title' => '...', 'createdAt' => (new \DateTime())->format('Y-m-d H:i:s')]; 
    $cache->save($latestNews->set($news)); 
} else { 
    $news = $latestNews->get(); 
} 

참조 http://symfony.com/doc/current/components/cache/cache_pools.html#filesystem-cache-adapter

처음으로, 캐시 파일 내용을 보여줍니다 :

2147483647 <-- 2038-01-18 22:14:07 :/ ? 
latest_news 
a:2:{s:5:"title";s:3:"...";s:9:"createdAt";s:19:"2016-10-07 09:16:50";} 

물론이 항목을 5 초 후에 만료되지 않습니다 :/(나는 캐시 디렉토리를 수동으로 삭제했다). 우리가 $latestNews->expiresAfter(5);를 사용하는 경우 다른 한편으로

은 모두 잘 작동합니다 :

1475849350 <-- 2016-10-07 10:09:10 \o/ OK 
latest_news 
a:2:{s:5:"title";s:3:"...";s:9:"createdAt";s:19:"2016-10-07 10:09:05";} 

참조 항목이 제대로 만료 http://symfony.com/doc/current/components/cache/cache_items.html#cache-item-expiration

오초 후.

Symfony\Component\Cache\Adapter\ApcuAdapter으로 테스트 한 결과 동일한 문제가 발생합니다.


캐시 어댑터의 기본 수명 (생성자 매개 변수)은 어떻게됩니까? 내가 여기에 뭔가를 놓친다 : /?

+0

이 버그가있는 이전 버전이 있는지 확인하십시오. https://github.com/symfony/symfony/pull/19442 – Matteo

+1

예, 감사합니다. @Matteo'작곡가 업데이트 '! – yceruto

+1

질문을 닫을 수 있도록 답을 달 수 있습니까? – Matteo

답변

1

오래된 문제를 해결해야 심포니 프레임 워크를 업그레이드 3.1

이전 프레임 워크 버전에 영향을 [Cache] Fix default lifetime being ignored입니다.

+1

... 또는 캐시 구성 요소를 업그레이드하면 문제가 해결됩니다.) – yceruto