[Cache] prevent getting older entries when the version key is evicted

This commit is contained in:
Nicolas Grekas 2018-09-23 09:05:27 +02:00
parent 9bc774ccf2
commit 00855895a8

View File

@ -106,14 +106,7 @@ trait AbstractTrait
{
$this->deferred = array();
if ($cleared = $this->versioningIsEnabled) {
$namespaceVersion = 2;
try {
foreach ($this->doFetch(array('@'.$this->namespace)) as $v) {
$namespaceVersion = 1 + (int) $v;
}
} catch (\Exception $e) {
}
$namespaceVersion .= ':';
$namespaceVersion = substr_replace(base64_encode(pack('V', mt_rand())), ':', 5);
try {
$cleared = $this->doSave(array('@'.$this->namespace => $namespaceVersion), 0);
} catch (\Exception $e) {
@ -247,6 +240,10 @@ trait AbstractTrait
foreach ($this->doFetch(array('@'.$this->namespace)) as $v) {
$this->namespaceVersion = $v;
}
if ('1:' === $this->namespaceVersion) {
$this->namespaceVersion = substr_replace(base64_encode(pack('V', time())), ':', 5);
$this->doSave(array('@'.$this->namespace => $this->namespaceVersion), 0);
}
} catch (\Exception $e) {
}
}