The configuration API is for storing and sharing system settings across environments. For local variables that shouldn't travel across environments (such as cron last run time), use the State API instead.
See the Configuration Management section for more details about managing configurations.
<?php
//Immutable Config (Read Only)
$config = \Drupal::config('system.performance');
$message = $config->get('message');
$page_cache = \Drupal::config('system.performance')->get('cache.page');
?>
<?php
//Mutable Config (Read / Write)
$config = \Drupal::service('config.factory')->getEditable('system.performance');
// Set a scalar value.
$config->set('cache.page.enabled', 1);
// Set an array of values.
$config->set('cache.page', ['enabled' => 1, 'max_age' => 5]);
// Save your data to the file system.
$config->save();
?>