Commit 0222983f authored by Narendra Shenvi Desai's avatar Narendra Shenvi Desai Committed by Peter Pajor
Browse files

Issue #3267748: Make depcalc cache persistent.

parent c6d8a646
Loading
Loading
Loading
Loading

drush.services.yml

0 → 100644
+6 −0
Original line number Diff line number Diff line
services:
  depcalc.commands:
    class: Drupal\depcalc\Commands\DepcalcCommands
    arguments: ['@depcalc.logger_channel', '@cache.depcalc']
    tags:
      - { name: drush.command }
+6 −0
Original line number Diff line number Diff line
name: Dependency Calculation UI
type: module
description: Provides UI for Dependency Calculation.
core_version_requirement: ^8.7.7 || ^9
dependencies:
  - drupal:depcalc
+26 −0
Original line number Diff line number Diff line
<?php

use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_form_FORM_ID_alter().
 */
function depcalc_ui_form_system_performance_settings_alter(&$form, FormStateInterface $form_state, $form_id) {
  $form['clear_cache']['clear_depcalc_cache'] = [
    '#type' => 'submit',
    '#value' => t('Clear depcalc cache'),
    '#name' => 'clear_depcalc_cache',
    '#submit' => ['submitDepcalcCacheClear'],
    '#suffix' => t('Hint: Clear all caches won\'t clear depcalc cache.')
  ];
}

/**
 * Clears the depcalc cache.
 */
function submitDepcalcCacheClear(array &$form, FormStateInterface $form_state) {
  /** @var \Drupal\depcalc\Cache\DepcalcCacheBackend $depcalc_cache */
  $depcalc_cache = \Drupal::service('cache.depcalc');
  $depcalc_cache->deleteAllPermanent();
  \Drupal::messenger()->addStatus(t('Cleared all depcalc cache.'));
}
+8 −0
Original line number Diff line number Diff line
@@ -160,6 +160,14 @@ class DepcalcCacheBackend implements CacheBackendInterface, CacheTagsInvalidator
   * {@inheritdoc}
   */
  public function deleteAll() {
    // This cache doesn't need to be deleted when doing cache rebuild.
    // We do nothing here.
  }

  /**
   * Deletes all cache items in a bin when explicitly called.
   */
  public function deleteAllPermanent(): void {
    $this->backend->deleteAll();
  }

+57 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\depcalc\Commands;

use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\depcalc\Cache\DepcalcCacheBackend;
use Drush\Commands\DrushCommands;

/**
 * Drush commands for Depcalc.
 *
 * @package Drupal\depcalc\Commands
 */
class DepcalcCommands extends DrushCommands {

  /**
   * Logger Service.
   *
   * @var \Drupal\Core\Logger\LoggerChannelInterface
   */
  protected $logger;

  /**
   * The Depcalc Cache backend.
   *
   * @var \Drupal\depcalc\Cache\DepcalcCacheBackend
   */
  protected $cache;

  /**
   * Public Constructor.
   *
   * @param \Drupal\Core\Logger\LoggerChannelInterface $logger
   *   The Depcalc logger channel.
   * @param \Drupal\depcalc\Cache\DepcalcCacheBackend $depcalc_cache
   *   The Depcalc Cache Backend.
   */
  public function __construct(LoggerChannelInterface $logger, DepcalcCacheBackend $depcalc_cache) {
    $this->logger = $logger;
    $this->cache = $depcalc_cache;
  }

  /**
   * Depcalc clear cache command.
   *
   * @usage depcalc:clear-cache
   *   This will clear depcalc cache.
   *
   * @command depcalc:clear-cache
   * @aliases dep-cc
   */
  public function clearDepcalcCache(): void {
    $this->cache->deleteAllPermanent();
    $this->logger()->success(dt('Cleared depcalc cache.'));
  }

}
Loading