8 – Disable caching for a front page path processor

I’m working on a project where users can create a book (core functionality). In a simple text field they can connect a domain to this book. This way the book is only accessible via this domain.

For example I have Book A with path node1 and with domain a.book.com. I also have Book B with path node2 and connected to domain b.book.com.

What I want now is if a visitor goes to a.book.com the frontpage is node/1. And if they go to b.book.com the frontpage should be node/2? I created a custom module for this book_frontpage.

For this I used large parts of the PathProcessorFront.php from core.

The code of my book_front.services.yml is:

    class: Drupalbook_frontpagePathProcessorFrontPagePathProcessor
      - { name: path_processor_inbound, priority: 300 }

The code of my FrontPagePathProcessor.php is:


namespace Drupalbook_frontpagePathProcessor;

use DrupalCoreDatabaseDatabase;
use DrupalCorePathProcessorInboundPathProcessorInterface;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpKernelExceptionNotFoundHttpException;

 * Path processor to replace 'node' with 'content' in URLs.
class FrontPagePathProcessor implements InboundPathProcessorInterface{
   * {@inheritdoc}
  public function processInbound($path, Request $request)
    if ($path === '/') {
      //current domain
      $currentDomain = $_SERVER('SERVER_NAME');

      //get nid of reader where domain is set
      $nid = Database::getConnection()->select('node__field_domain', 'd')
        ->fields('d', ('entity_id'))
        ->condition('field_domain_value', $currentDomain, '=')

      //get path
      $path = Drupal::service('path_alias.manager')->getAliasByPath('/node/'. $nid);

      if (empty($path)) {
        // We have to return a valid path but / won't be routable and config
        // might be broken so stop execution.
        throw new NotFoundHttpException();
      $components = parse_url($path);

      // Remove query string and fragment.
      $path = $components('path');

      // Merge query parameters from front page configuration value
      // with URL query, so that actual URL takes precedence.
      if (!empty($components('query'))) {
        parse_str($components('query'), $parameters);
        array_replace($parameters, $request->query->all());

    return $path;

Now when going to a.book.com I see node/1 but when I go to b.book.com I also see node/1. When I clear cache and first go to b.book.com I get node/2 but when going to a.book.com I also get node/2. So this looks like a cache problem.

How can I disable caching of this front page path?