Bye bye CTools object cache, hello Private TempStore

I Drupal 7, the CTools object cache was my go-to for storing data between page requests while a user uses a multi-step form. Drupal 8 introduces the Tempstore, specifically the Private TempStore, and is very similar to the CTools object cache in that it uses the user session and stores the data in the database for a limited time (7 days).

Here is what the docs say about Private TempStore:

A PrivateTempStore can be used to make temporary, non-cache data available across requests. The data for the PrivateTempStore is stored in one key/value collection. PrivateTempStore data expires automatically after a given timeframe.

The PrivateTempStore is different from a cache, because the data in it is not yet saved permanently and so it cannot be rebuilt. Typically, the PrivateTempStore might be used to store work in progress that is later saved permanently elsewhere, e.g. autosave data, multistep forms, or in-progress changes to complex configuration that are not ready to be saved.

I am using the Private TempStore instead of the Shared TempStore because:

The PrivateTempStore differs from the SharedTempStore in that all keys are ensured to be unique for a particular user and users can never share data.

Below is an example of how to use Private TempStore:

<?php

namespace Drupal\module_name;

use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Session\SessionManagerInterface;
use Drupal\user\PrivateTempStoreFactory;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

/**
 * Class Example.
 *
 * @package Drupal\module_name
 */
class Example {

  /**
   * @var \Drupal\user\PrivateTempStoreFactory
   */
  protected $tempStoreFactory;

  /**
   * @var \Drupal\Core\Session\SessionManagerInterface
   */
  private $sessionManager;

  /**
   * @var \Drupal\Core\Session\AccountInterface
   */
  private $currentUser;

  /**
   * @var \Drupal\user\PrivateTempStore
   */
  protected $store;

  /**
   * @var \Symfony\Component\HttpFoundation\Session\SessionInterface
   */
  protected $session;

  /**
   * Constructor.
   */
  public function __construct(PrivateTempStoreFactory $temp_store_factory, SessionManagerInterface $session_manager, AccountInterface $current_user, SessionInterface $session) {
    $this->tempStoreFactory = $temp_store_factory;
    $this->sessionManager = $session_manager;
    $this->currentUser = $current_user;
    $this->session = $session;

    // The collection name to use for this key/value store. This is typically a
    // shared namespace or module name, e.g. 'views', 'entity', etc.
    $collection = 'collection_name';
    $this->store = $this->tempStoreFactory->get($collection);
  }

  /**
   * Set storage data.
   *
   * @var $data
   *   The data to save.
   */
  public function setStorage($data) {
    // If user is anonymous, create a session.
    if ($this->currentUser->isAnonymous() && !$this->sessionManager->isStarted()) {
      $this->session->migrate();
    }
    $this->store->set('values', $data);
  }

  /**
   * Get storage data.
   */
  public function getStorage() {
    return $this->store->get('values');
  }

}