/** * Create a new instance of the cache and driver. * * @param string|null $name The connection name * @param Config|null $config The config for the instance */ public function __construct($name = null, Config $config = null) { // If a name isn't provided, then we'll use the default $this->name = $name ?: 'default'; // Load the config if it isn't passed in if ($config === null) { $config = Cache::config()->{$this->name}; } // If config is still null, then throw an exception if ($config === null) { throw new ConfigNotFoundException('No config could be found for instance ' . $this->name . '.'); } // Set the name in the config as some drivers need it $config->name = $this->name; // Create a cache namespace key $this->key = hash('adler32', $name); // If the driver isn't created, throw an exception if (!isset($this->drivers[$config->driver])) { throw new InvalidDriverException($config->driver . ' is not a valid driver.'); } // Initialise the driver $driverClass = $this->drivers[$config->driver]; $this->driver = new $driverClass($config, $this); }
/** * Set a config value. * * @param string $path The path of the value to set * @param mixed $value The value to set * * @return mixed The value */ public static function set($key, $value = null) { return Cache::config()->setValueForPath($key, $value); }