W3cubDocs

/Drupal 8

function system_cron

system_cron()

Implements hook_cron().

Remove older rows from flood, batch cache and expirable keyvalue tables.

File

core/modules/system/system.module, line 1275
Configuration system that lets administrators modify the workings of the site.

Code

function system_cron() {
  // Clean up the flood.
  \Drupal::flood()->garbageCollection();

  foreach (Cache::getBins() as $cache_backend) {
    $cache_backend->garbageCollection();
  }

  // Clean up the expirable key value database store.
  if (\Drupal::service('keyvalue.expirable.database') instanceof KeyValueDatabaseExpirableFactory) {
    \Drupal::service('keyvalue.expirable.database')->garbageCollection();
  }

  // Clean up any garbage in the queue service.
  $queue_worker_manager = \Drupal::service('plugin.manager.queue_worker');
  $queue_factory = \Drupal::service('queue');

  foreach (array_keys($queue_worker_manager->getDefinitions()) as $queue_name) {
    $queue = $queue_factory->get($queue_name);

    if ($queue instanceof QueueGarbageCollectionInterface) {
      $queue->garbageCollection();
    }
  }

  // Clean up PHP storage.
  PhpStorageFactory::get('container')->garbageCollection();
  PhpStorageFactory::get('service_container')->garbageCollection();
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!system!system.module/function/system_cron/8.1.x