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

makeCache() public method

Transfer the contents of the parent Vars object into a file for cache
public makeCache ( Vars $vars )
$vars M1\Vars\Vars Parent vars object
    public function makeCache(Vars $vars)
    {
        if ($this->provide) {
            $cache_folder = sprintf("%s/vars", $this->path);
            if (!file_exists($cache_folder)) {
                mkdir($cache_folder, 0777, true);
            }
            $cache_file = sprintf('%s/%s.php', $cache_folder, $this->name);
            file_put_contents($cache_file, serialize($vars));
        }
    }

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);
     }
 }