In Drupal 7 and earlier, system configuration and state were commingled in the variables table. In addition to the new Configuration API, Drupal 8 added the State API. This should be used for settings that are:
- Specific to an individual environment and should not be deployed between environments
- Can be reset without adverse consequences
This encompasses items such as the last cron run timestamp, CSRF tokens, and so on. Typical uses include:
- Getting a state variable:
$val = \Drupal::state()->get('key');
- Setting a state variable:
\Drupal::state()->set('key', 'value');
- Deleting a state variable:
\Drupal::state()->delete('key');