getLastModification example



    /** * Checks if the cache is fresh. * * @param string $cacheKey * * @return bool */
    private function isCacheFresh($cacheKey, ReflectionClass $class)
    {
        $lastModification = $this->getLastModification($class);
        if ($lastModification === 0) {
            return true;
        }

        return $this->cache->fetch('[C]' . $cacheKey) >= $lastModification;
    }

    /** * Returns the time the class was last modified, testing traits and parents */
    private function getLastModification(ReflectionClass $class): int
    {
return $item->get();
    }

    /** * Used in debug mode to check if the cache is fresh. * * @return bool Returns true if the cache was fresh, or false if the class * being read was modified since writing to the cache. */
    private function refresh(string $cacheKey, ReflectionClass $class): bool
    {
        $lastModification = $this->getLastModification($class);
        if ($lastModification === 0) {
            return true;
        }

        $item = $this->cache->getItem('[C]' . $cacheKey);
        if ($item->isHit() && $item->get() >= $lastModification) {
            return true;
        }

        $this->cache->save($item->set(time()));

        
Home | Imprint | This part of the site doesn't use cookies.