D9+ Multi-Domain and Multisite support

Created on 21 June 2023, almost 2 years ago

Problem/Motivation

Unlike the D7 Version of this module a domain/multisite support is not part of D9+ version yet.

Steps to reproduce

Currently not tested because I don't have a multisite setup available. Whoever can reproduce the proble is invited to test upcoming fetaure

Proposed resolution

I think the most important thing is to just add the option to extend the "file cache" paths with domain name for writing an retrieving the files. This will be a minimal support. But if somebody wants to handle different configuration and purging etc. it seems better to just set different cache folders. This feature is already prepared. But because in my company we currently don't have any multisite setups it would be very helpful if somebody will help with testing of multisites.

Remaining tasks

Implement domain path in code.

User interface changes

Only if we want to make this configurable.

API changes

-

Data model changes

Because cache file paths will change which is not really a data model we just need
a complete cache purge and everthin works.

Feature request
Status

Active

Version

1.0

Component

Caching logic

Created by

🇩🇪Germany c-logemann Frankfurt/M, Germany

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @c-logemann
  • 🇩🇪Germany c-logemann Frankfurt/M, Germany
  • First commit to issue fork.
  • 🇧🇪Belgium davidiio

    Hello,

    We need this on our project so I worked on it and just created an issue fork.
    I just added a "Use domain" field on configuration form and then use that in BoostCacheFile.php prepend (or not) the current domain to the uri.

    We used that on some test site and it works, with or without domain cache files are created when visiting pages.

    One inconsistency though is that when purging in admin interface it is purging every files for every domain while for generating files it generates only for current domain. So one improvement would be to harmonize how it is working there, or give possibility to generate or purge by domain or for all at once (but requires boost to know for which domains to generate cache files)

  • 🇩🇪Germany c-logemann Frankfurt/M, Germany
  • 🇮🇳India abhishek@kumar

    Path Generation:

    // In BoostCache.php or similar
    protected function getCachePath() {
      $base_path = parent::getCachePath();
      if ($this->config->get('multisite_support')) {
        $base_path = $base_path . '/' . \Drupal::request()->getHost();
      }
      return $base_path;
    }
    

    Settings Form Addition:

    // In BoostSettingsForm.php
    $form['multisite'] = [
    '#type' => 'details',
    '#title' => $this->t('Multisite settings'),
    '#open' => FALSE,
    ];

    $form['multisite']['enable_domain_paths'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Enable domain-specific cache paths'),
      '#default_value' => $config->get('enable_domain_paths'),
      '#description' => $this->t('When enabled, each domain will get its own cache subdirectory.'),
    ];
    
  • 🇧🇪Belgium davidiio

    Thanks abhishek@kumar,

    I have already done similar changes in the issue fork.
    I'd like to have maintainers feedback before making a merge request or imprivement. Or maybe I should make it a merge request to get feedback?

  • 🇧🇪Belgium davidiio

    For consistency I have also edited getCachedFiles() to get only cached files by domain and be more precise in the description of the use_domain configuration field.

    Now when using domain:
    - Cache files are separated in domain related directories
    - Purge and Generation works only on domain you are currently logged in.

    I have just noticed while writing this, that the purge on boost_cron() method will work only on base domain so I still have to work on this.

  • 🇩🇪Germany c-logemann Frankfurt/M, Germany

    The solution for domains in cache file path is similar as on old D7 version. In this way multi domain is possible. But when thinking of multisite (which I didn't used since more than a decade) this can be solved with individual base caching paths configured in each multisite database. So I think we don't need extra support for this when setting a custom path ist working well. This needs a separate Issue I think. So let's focus on multi domain in this issue.

  • 🇩🇪Germany c-logemann Frankfurt/M, Germany

    On the other side a domain based caching path inside is maybe enough for many multisite setups.

Production build 0.71.5 2024