Skip to content

Commit

Permalink
Merge pull request #339 from Bixal/feature/BSD-338-cache-clear-bug
Browse files Browse the repository at this point in the history
BSD fixes #338: Allow cache to be cleared with Drush again.
  • Loading branch information
mattsqd authored Nov 22, 2024
2 parents f86197f + c2c1eca commit da4b684
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 113 deletions.
17 changes: 9 additions & 8 deletions web/sites/default/settings.lando.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,22 @@
if (isset($lando_info->cache->type)) {
switch ($lando_info->cache->type) {
case 'redis':
require 'settings.redis.php';
if (function_exists('_settings_redis')) {
_settings_redis(
require_once 'settings.redis.php';
if (function_exists('_drupal_env_settings_redis')) {
_drupal_env_settings_redis(
$settings,
$lando_info->cache->internal_connection->host,
$lando_info->cache->internal_connection->port
$lando_info->cache->internal_connection->port,
'PhpRedis',
);
}
break;

case 'memcached':
require 'settings.memcache.php';
if (function_exists('_settings_memcache')) {
$memcache_host = implode(':', (array)$lando_info->cache->internal_connection);
_settings_memcache($settings, $memcache_host);
require_once 'settings.memcache.php';
if (function_exists('_drupal_env_settings_memcache')) {
$memcache_host = implode(':', (array) $lando_info->cache->internal_connection);
_drupal_env_settings_memcache($settings, $memcache_host);
}
break;

Expand Down
65 changes: 38 additions & 27 deletions web/sites/default/settings.memcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,52 @@

use Drupal\Core\Installer\InstallerKernel;

if ((
if (
!InstallerKernel::installationAttempted() &&
(extension_loaded('memcached') || extension_loaded('memcache')) &&
file_exists($app_root . '/modules/contrib/memcache') &&
!function_exists('_settings_memcache')
)) {
function _settings_memcache(array &$settings, string $host): void {
file_exists($app_root . '/modules/contrib/memcache')
) {
/**
* Apply Memcache cache settings.
*
* Drush can be bootstrap Drupal twice, this should be safe to be called
* multiple times.
*
* @param array $settings
* The $settings array from settings.php.
* @param string $host
* The host that Memcache will be contacted on.
*
* @return void
*/
function _drupal_env_settings_memcache(array &$settings, string $host): void {
$settings['memcache']['servers'][$host] = 'default';
}

# Use for all bins otherwise specified.
$settings['cache']['default'] = 'cache.backend.memcache';
// Use for all bins otherwise specified.
$settings['cache']['default'] = 'cache.backend.memcache';

/* Optional settings:
// Optional settings:
Apply changes to the container configuration to better leverage Memcache.
This includes using Memcache for the lock and flood control systems, as well
as the cache tag checksum. Alternatively, copy the contents of that file
to your project-specific services.yml file, modify as appropriate, and
remove this line. */
$settings['container_yamls'][] = 'modules/contrib/memcache/example.services.yml';

// Apply changes to the container configuration to better leverage Redis.
// This includes using Memcache for the lock and flood control systems, as well
// as the cache tag checksum. Alternatively, copy the contents of that file
// to your project-specific services.yml file, modify as appropriate, and
// remove this line.
$settings['container_yamls'][] = 'modules/contrib/memcache/example.services.yml';
// Allow the services to work before the Memcache module itself is enabled.
$settings['container_yamls'][] = 'modules/contrib/memcache/memcache.services.yml';

// Allow the services to work before the Redis module itself is enabled.
$settings['container_yamls'][] = 'modules/contrib/memcache/memcache.services.yml';
// Use Memcache for container cache.
// The container cache is used to load the container definition itself, and
// thus any configuration stored in the container itself is not available
// yet. These lines force the container cache to use Memcache rather than the
// default SQL cache.
require 'settings.memcache.container_pure.php';
}

// These only need to be done once, then they are included and applied always.
// Manually add the classloader path, this is required for the container cache bin definition below
// and allows to use it without the redis module being enabled.
// and allows to use it without the Memcache module being enabled.
$class_loader->addPsr4('Drupal\\memcache\\', 'modules/contrib/memcache/src');

require 'settings.memcache.container_pure.php';
}







73 changes: 22 additions & 51 deletions web/sites/default/settings.platformsh.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,57 +42,28 @@
}

// Enable Redis caching.
if ($platformsh->hasRelationship('redis') && !InstallerKernel::installationAttempted() && extension_loaded('redis') && class_exists('Drupal\redis\ClientFactory')) {
$redis = $platformsh->credentials('redis');

// Set Redis as the default backend for any cache bin not otherwise specified.
$settings['cache']['default'] = 'cache.backend.redis';
$settings['redis.connection']['host'] = $redis['host'];
$settings['redis.connection']['port'] = $redis['port'];

// Apply changes to the container configuration to better leverage Redis.
// This includes using Redis for the lock and flood control systems, as well
// as the cache tag checksum. Alternatively, copy the contents of that file
// to your project-specific services.yml file, modify as appropriate, and
// remove this line.
$settings['container_yamls'][] = 'modules/contrib/redis/example.services.yml';

// Allow the services to work before the Redis module itself is enabled.
$settings['container_yamls'][] = 'modules/contrib/redis/redis.services.yml';

// Manually add the classloader path, this is required for the container cache bin definition below
// and allows to use it without the redis module being enabled.
$class_loader->addPsr4('Drupal\\redis\\', 'modules/contrib/redis/src');

// Use redis for container cache.
// The container cache is used to load the container definition itself, and
// thus any configuration stored in the container itself is not available
// yet. These lines force the container cache to use Redis rather than the
// default SQL cache.
$settings['bootstrap_container_definition'] = [
'parameters' => [],
'services' => [
'redis.factory' => [
'class' => 'Drupal\redis\ClientFactory',
],
'cache.backend.redis' => [
'class' => 'Drupal\redis\Cache\CacheBackendFactory',
'arguments' => ['@redis.factory', '@cache_tags_provider.container', '@serialization.phpserialize'],
],
'cache.container' => [
'class' => '\Drupal\redis\Cache\PhpRedis',
'factory' => ['@cache.backend.redis', 'get'],
'arguments' => ['container'],
],
'cache_tags_provider.container' => [
'class' => 'Drupal\redis\Cache\RedisCacheTagsChecksum',
'arguments' => ['@redis.factory'],
],
'serialization.phpserialize' => [
'class' => 'Drupal\Component\Serialization\PhpSerialize',
],
],
];
if ($platformsh->hasRelationship('redis')) {
require_once 'settings.redis.php';
if (function_exists('_drupal_env_settings_redis')) {
$redis = $platformsh->credentials('redis');
_drupal_env_settings_redis(
$settings,
$redis['host'],
$redis['port'],
'PhpRedis',
);
}
}
// Enable Memcached caching.
if ($platformsh->hasRelationship('memcached')) {
require_once 'settings.memcache.php';
if (function_exists('_drupal_env_settings_memcache')) {
$memcached = $platformsh->credentials('memcached');
_drupal_env_settings_memcache(
$settings,
$memcached['host'] . ':' . $memcached['port']
);
}
}

if ($platformsh->inRuntime()) {
Expand Down
73 changes: 46 additions & 27 deletions web/sites/default/settings.redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,60 @@

use Drupal\Core\Installer\InstallerKernel;

if ((
if (
!InstallerKernel::installationAttempted() &&
extension_loaded('redis') &&
class_exists('Drupal\redis\ClientFactory') &&
!function_exists('_settings_redis')
)) {
function _settings_redis(array &$settings, string $host, string $port): void {
class_exists('Drupal\redis\ClientFactory')
) {
/**
* Apply Redis cache settings.
*
* Drush can be bootstrap Drupal twice, this should be safe to be called
* multiple times.
*
* @param array $settings
* The $settings array from settings.php.
* @param string $host
* The host that Redis will be contacted on.
* @param string $port
* The port that Redis will be contacted on.
* @param string $interface
* This can be 'Relay', 'PhpRedis', or 'Predis'. PhpRedis is fastest, Predis
*
* @return void
*/
function _drupal_env_settings_redis(array &$settings, string $host, string $port, string $interface = ''): void {
$settings['redis.connection']['host'] = $host;
$settings['redis.connection']['port'] = $port;
if (!empty($interface)) {
$settings['redis.connection']['interface'] = $interface;
}
// Use for all bins otherwise specified.
$settings['cache']['default'] = 'cache.backend.redis';

/* Optional settings:
Apply changes to the container configuration to better leverage Redis.
This includes using Redis for the lock and flood control systems, as well
as the cache tag checksum. Alternatively, copy the contents of that file
to your project-specific services.yml file, modify as appropriate, and
remove this line. */
$settings['container_yamls'][] = 'modules/contrib/redis/example.services.yml';

// Allow the services to work before the Redis module itself is enabled.
$settings['container_yamls'][] = 'modules/contrib/redis/redis.services.yml';

// Use redis for container cache.
// The container cache is used to load the container definition itself, and
// thus any configuration stored in the container itself is not available
// yet. These lines force the container cache to use Redis rather than the
// default SQL cache.
require 'settings.redis.container.php';
}

$settings['redis.connection']['interface'] = 'PhpRedis'; // Can be "Predis".
# Use for all bins otherwise specified.
$settings['cache']['default'] = 'cache.backend.redis';

// Optional settings:

// Apply changes to the container configuration to better leverage Redis.
// This includes using Redis for the lock and flood control systems, as well
// as the cache tag checksum. Alternatively, copy the contents of that file
// to your project-specific services.yml file, modify as appropriate, and
// remove this line.
$settings['container_yamls'][] = 'modules/contrib/redis/example.services.yml';

// Allow the services to work before the Redis module itself is enabled.
$settings['container_yamls'][] = 'modules/contrib/redis/redis.services.yml';

// These only need to be done once, then they are included and applied always.
// Manually add the classloader path, this is required for the container cache bin definition below
// and allows to use it without the redis module being enabled.
$class_loader->addPsr4('Drupal\\redis\\', 'modules/contrib/redis/src');

require 'settings.redis.container.php';
}





0 comments on commit da4b684

Please sign in to comment.