public function testExpiredCacheElement() { $now = new \DateTime(); $element = new CacheElement('foo', 'bar', 0, $now->sub(new \DateInterval('PT1S'))); $this->assertTrue($element->isExpired()); $this->assertEquals(new \DateTime(), $element->getExpirationDate()); }
/** * {@inheritdoc} */ public function get($key) { $file = $this->getCacheKey($key); if ($this->filesystem->exists($file)) { $data = (include $file); $element = new CacheElement($key, unserialize($data['data']), $data['ttl'], new \DateTime('@' . $data['createdAt'])); if (!$element->isExpired()) { return $element; } } return $this->createInvalidElement($key); }