M1\Vars\Cache\CacheProvider::checkCache PHP Method

checkCache() public method

Checks the cache to see if there is a valid cache available
public checkCache ( ) : boolean
return boolean Returns true if has the cached resource
    public function checkCache()
    {
        if ($this->provide && $this->path && !$this->getAttempted()) {
            $file = sprintf('%s/vars/%s.php', $this->path, $this->name);
            $this->attempted = true;
            if (is_file($file) && filemtime($file) >= time() - $this->expire) {
                $this->hit = true;
                return true;
            }
        }
        return false;
    }

Usage Example

Example #1
0
 /**
  * Creates a new instance of Vars
  *
  * @param string|array $resource The main configuration resource
  * @param array        $options  The options being used for Vars
  */
 public function __construct($resource, $options = array())
 {
     $options = $this->parseOptions($options);
     $this->makeCache($options, $resource);
     $this->makePaths($options);
     if (!$this->cache->checkCache()) {
         $this->makeLoader($options);
         $this->makeVariables($options);
         $resource = new ResourceProvider($this, $resource);
     }
     if ($this->cache->isHit()) {
         $this->loadFromCache();
     } else {
         $resource->mergeParentContent();
         $this->content = $resource->getContent();
         $this->cache->setTime(time());
         $this->cache->makeCache($this);
     }
 }