Clear an item if it expired.

@param          $key
@param DateTime $dateTime
543163
private function clearExpiredKey($key, DateTime $dateTime)
    {
        if (self::$registry[$key]['expires'] < $dateTime) {
            unset(self::$registry[$key]);
        }
    }
1301314
public function getFor($key, \DateTime $date)
    {
        if (!$this->hasFor($key, $date)) {
            return null;
        }

        return $this->data[$this->keyFor($key, $date)];
    }
703620
public function remove(string $key): void
    {
        $this->items = Arr::remove($this->items, $key);
    }
740123
public function getExpiration($key, $dateTimeObject = true)
    {
        $ttl = $this->getRedis()->ttl($key);

        if (-2 === $ttl) {
            throw CacheException::keyNotExist($key, 'RedisDriver::getExpiration');
        } elseif (-1 === $ttl) {
            return null;
        } else {
            if ($dateTimeObject) {
                return new \DateTime('+ ' . $ttl . ' seconds', new \DateTimeZone('UTC'));
            } else {
                return $ttl;
            }
        }
    }
631667
public function clear()
    {
        $currentDate = new DateTime();
        foreach (\array_keys(self::$registry) as $key) {
            $this->clearExpiredKey($key, $currentDate);
        }
    }
256921
protected function forgetExpiredViews(string $key)
    {
        $currentTime = Carbon::now();
        $viewHistory = $this->session->get($key, []);

        foreach ($viewHistory as $record) {
            if ($record['expires_at']->lte($currentTime)) {
                $recordId = array_search($record['viewable_id'], array_column($record, 'viewable_id'));

                $this->session->pull($key.$recordId);
            }
        }
    }
1167891
public function hasFor($key, \DateTime $date)
    {
        return array_key_exists($this->keyFor($key, $date), $this->data);
    }
314494
public function delete($key)
	{
		parent::delete($key);

		// Reindex the array to eliminate any gaps
		$this->items = array_values($this->items);
	}
1157681
public function endOfMonth(\DateTime $datetime)
	{
		$year = $datetime->format('Y');
		$month = $datetime->format('m');
		$day = $datetime->format('t');

		$datetime->setDate($year, $month, $day);
	}
1197303
public function clearLogin($key)
    {
        $key = $this->getKey($key);
        
        // 清除Cookie
        Cookie::delete($key);
        
        // 清除Cache
        $ticket = Cookie::get($key);
        $ticket && Cache::rm($ticket);
    }
1134368
public function removeForRange($key, \DateTime $start, \DateTime $end)
    {
        unset($this->data[$this->keyForRange($key, $start, $end)]);
    }
159750
protected function removeForPeriod($key, \DatePeriod $period)
    {
        $ranges = $this->getRanges($period);

        if (count($ranges) > 0) {
            foreach ($ranges as $range) {
                $range instanceof DateRange
                    ? $this->repository->removeForRange($key, $range->getStartDate(), $range->getEndDate())
                    : $this->repository->removeFor($key, $range);
            }
        }
    }
687956
static function setLastChecked( $id, $dateTime = false )
    {
        if ( $dateTime === false )
        {
            $dateTime = time();
        }
        eZPersistentObject::updateObjectList( array( 'definition' => eZURL::definition(),
                                                     'update_fields' => array( 'last_checked' => $dateTime ),
                                                     'conditions' => array( 'id' => $id ) ) );
    }
761375
public function setExpirationTime($expirationTime)
    {
        if (is_a($expirationTime, 'DateTime')) {
            $this->expirationTime = $expirationTime;
        } else if (is_numeric($expirationTime)) {
            $expirationDateTime = new \DateTime('', new \DateTimeZone("UTC"));
            $expirationDateTime->setTimestamp($expirationTime);
            $this->expirationTime = $expirationDateTime;
        }
        return $this;
    }
965629
public function setExpire(\DateTime $expire = null)
    {
        $this->_expire = ($expire) ? $expire : null;

        return $this;
    }
1358067
private function removeExpired($key): bool
    {
        if (
            \array_key_exists($key, self::$expired) === false
            ||
            \array_key_exists($key, self::$values) === false
        ) {
            return false;
        }

        list($time, $ttl) = self::$expired[$key];

        if (\time() > ($time + $ttl)) {
            unset(self::$values[$key]);
        }

        if (!isset(self::$values[$key])) {
            unset(self::$expired[$key]);
        }

        return true;
    }
687125
public function expires($key)
    {
        if (!isset($this->records[$key])) {
            return 0;
        }

        return (int) max(0, $this->records[$key]['expire'] - time());
    }